警告:session_start():无法发送会话cookie - 已经发送的标头(输出开始于

Gee*_*tha 28 html php mysql

登录页面中出现以下警告:它在localhost中工作,但在远程主机中不工作

警告: session_start()[function.session-start]:无法发送会话cookie - 已经发送的标头(输出从第8行开始)

警告: session_start()[function.session-start]:无法发送会话缓存限制器 - 已发送的标头(输出从第8行开始)

在此输入图像描述

的index.php

<?php
session_start();
if(isset($_SESSION['usr']) && isset($_SESSION['pswd'])){
header('Location: content.php');}
?>
<body>
<center>
<form method='post' action='login.php'>
<!– in this example I link it with login.php to check the password & username–>
<table>
<tr><td>Username:</td><td><input type='text' name='usr'></td></tr>
<tr><td>Password:</td><td><input type='password' name='pswd'></td>
</tr>
<tr><td><input type='submit' name='login' value='Login'></td>
<td><input type='reset' name='reset' value='Reset'></td></tr>
</table>
</form>
</center>
</body>  
Run Code Online (Sandbox Code Playgroud)

content.php

<body>
<a href="resumedownload.php">Click here to Download to Resume</a>
<?php
session_start();
if(!isset($_SESSION["usr"]) || !isset($_SESSION["pswd"])){
 header('Location: index.php');}
include 'logoff.php';
?>
</body>
Run Code Online (Sandbox Code Playgroud)

的login.php

<body>
<?php
session_start();
if($_REQUEST['usr']=='suman.trytek' && $_REQUEST['pswd']=='solutions'){
$_SESSION['usr'] = 'suman.trytek';
$_SESSION['pswd'] = 'solutions';
header('Location: content.php');
}
else{
header('Location: index.php');
}
?>
</body>
Run Code Online (Sandbox Code Playgroud)

Kri*_*h R 58

session_start();始终移动到页面顶部.

<?php
@ob_start();
session_start();
?>
Run Code Online (Sandbox Code Playgroud)

  • 检查您是否未使用BOM保存(也称为Unicode签名).我尝试了一切,BOM就是问题所在.如果您使用的是UTF-8文件,这很常见. (2认同)

Fra*_*ank 9

  1. session_start()必须位于源代码的顶部,没有html或其他输出!
  2. 你只能发送一次session_start()
  3. 通过这种方式 if(session_status()!=PHP_SESSION_ACTIVE) session_start()

  • http://stackoverflow.com/questions/6249707/check-if-php-session-has-already-started (2认同)