这可能会被视为“重复”,但我已经阅读了关于这个问题的最重要的帖子,因为可悲的是
session_start();
在顶部似乎对我不起作用,因为这是最有建议的答案。
除此之外,我在20 - 30分钟前将其上传到我的网站,但它与Xammp一起工作正常,可能是不同的PHP版本。
这是我的代码和错误:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 2
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at /home/corrupts/public_html/index.php:29) in /home/corrupts/public_html/pages/examples/session.php on line 33
代码:
<?php
session_start();
include('config.php');
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"select * from users where email = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_id = $row['id'];
$login_session = $row['email'];
$login_password = $row['password'];
$rank = $row['rank'];
$join_date = $row['joined'];
$bio = $row['bio'];
$credits = $row['credits'];
$adminlevel = $row['adminlevel'];
$banned = $row['banned'];
//Get stats
$ses_sql = mysqli_query($db,"select * from stats");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$sales = $row['sales'];
$members = $row['members'];
$vip = $row['vips'];
if(!isset($_SESSION['login_user'])){
header("location: login.php");
}
&GT;
答案 0 :(得分:0)
警告:session_start():无法发送会话cookie - 已在/home/corrupts/public_html/pages/examples/session.php中发送的报头(输出从/home/corrupts/public_html/index.php:29开始)在第2行
错误清楚地说明了问题
(输出于/home/corrupts/public_html/index.php:29开始)
已经在index.php 的第29行发出了标题(你已经在index.php中启动了一个会话) 这可能是session.php第2行的相同代码。 的 /home/corrupts/public_html/pages/examples/session.php 强>
注意:最好检查会话是否已存在,使用相同的会话而不是重新创建另一个会话。您可以通过将以下代码添加到需要会话的页面顶部来实现。
if( empty( session_id() ) )
{
session_start();
)
希望它有所帮助!