【发布时间】:2014-02-26 14:37:05
【问题描述】:
登录页面出现以下警告:它在本地主机中工作,但在远程主机中不工作
警告: 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>
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>
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>
【问题讨论】:
-
它由于多个标头位置发送,因此您可以在 之后的顶部使用
-
在我的情况下,我必须设置没有 BOM 的文件编码。