简体   繁体   English

PHP 错误无法发送会话缓存限制器 - 标头已发送

[英]PHP Error Cannot send session cache limiter - headers already sent

Hello I have three PHP codes where one page I have is of index.php where I am scanning the username and password from the user and then sending it to another file userlogin_process.php where I am first starting the session and then I am matching the scanned values with the database and if they match I am storing them into session variable but it shows me 2 warnings on that page Cannot send session cache limiter - headers already sent and last page I have is of user_session.php where I am locating the user to the home page of the website.您好,我有三个 PHP 代码,其中一个页面是index.php ,我在其中扫描用户的用户名和密码,然后将其发送到另一个文件userlogin_process.php ,在那里我首先启动会话,然后匹配与数据库扫描的值,如果它们匹配,我将它们存储到会话变量中,但它在该页面上向我显示 2 个警告无法发送会话缓存限制器 - 标题已发送,我拥有的最后一页是user_session.php ,我在其中定位用户到网站的主页。

index.php索引.php

session_start();
<form method="post" action="userlogin_process.php">
<div class="p">User Login</div>  
<table style="margin-top:5%;margin-left:12%;">
<tr><td> <label style="font-size:16px"> UserName :</label></td></tr>
<tr><td><input class="input" type="text" name="username" placeholder="FirstName"/></td></tr>
<tr><td><label style="font-size:16px">Password :</label></td></tr>
<tr><td><input class="input" type="password" name="userpass" placeholder="Mobile No"/></td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td align="center"><input class="button" type="submit" name="usersubmit" value="Login"/></td></tr>
</table>
</form>

user_loginprocess.php user_loginprocess.php

<?php 
session_start();
include("db.php");
$uname = $_POST['username'];
$upass = $_POST['userpass'];
echo $uname;
echo $upass;
$sql = mysql_query("select id,fname,mobile from user where fname='$uname'") or die(mysql_error());
$count = mysql_num_rows($sql);
if ($count > 0){
while($row = mysql_fetch_array($sql)){
$id = $row['id'];
$fname = $row['fname'];
$mobile = $row['mobile'];
}
}
if( $uname == $fname && $upass == $mobile ){
$_SESSION['uid'] = $id; 
$_SESSION['username'] = $fname;
$_SESSION['usermobile'] = $mobile;
$_SESSION['login'] = "yes";
header('location:user_session.php');
}
else{       
header('location:index.php?msg=incorrect');
} 
?> 

user_sesssion.php用户会话.php

<?php 
 session_start();
if( isset($_SESSION['login']) == "yes"){
header('location:user_detail.php?pageno=1');
} 
else{   
header('location:index.php?msg=login');
}
 ?>

First thing i can see is that you use session_start() multiple times.我能看到的第一件事是您多次使用session_start() as you can see it in their docs that will not create any harm but it may throw an error or warnings.. so it is better to stick to use only once.正如您在他们的文档中看到的那样,它不会造成任何伤害,但可能会引发错误或警告......所以最好坚持只使用一次。

Second please use mysqli_* docs since my_sql is deprecated.二,请使用mysqli_*文档,因为my_sql已被弃用。 or PDO .PDO

and this part looks off::这部分看起来不对:

session_start();
<form method="post" action="userlogin_process.php">

it should be:它应该是:

<?php session_start(); ?>
<form method="post" action="userlogin_process.php">

but either way is wrong since session should be stared in top of the page.但无论哪种方式都是错误的,因为会话应该盯着页面顶部。 and last try to fix all those small mistakes, it may work or throw another error, which in either case is good, since is moving forwards :)最后尝试修复所有这些小错误,它可能会起作用或引发另一个错误,这在任何一种情况下都是好的,因为正在向前发展:)

To stop sending header very early it is good to buffer output and send at the end of script.要尽早停止发送标头,最好缓冲输出并在脚本末尾发送。 For this turn on buffering in php.ini.为此,请在 php.ini 中打开缓冲。

output_buffering = On

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 随机无法发送会话缓存限制器 - 已发送的标头 - Random Cannot send session cache limiter - headers already sent PyroCMS-无法发送会话缓存限制器-标头已发送 - PyroCMS - Cannot send session cache limiter - headers already sent PHP警告:session_start():无法发送会话缓存限制器-标头已发送 - PHP Warning: session_start(): Cannot send session cache limiter - headers already sent 无法发送会话缓存限制器 - 标头已发送 - CodeIgniter (Session.php) - Cannot send session cache limiter - headers already sent - CodeIgniter (Session.php) 解决“连接超时”错误后,发生“无法发送会话缓存限制器-标头已发送”错误 - “Cannot send session cache limiter - headers already sent” error occurs after solving “Connection timeout” error 警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送 - Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent 在localhost上有效,但在Web服务器上不起作用... session_start():无法发送会话缓存限制器-标头已发送 - Works on localhost but not on web server…session_start(): Cannot send session cache limiter - headers already sent 故障排除“警告:session_start():无法发送会话缓存限制器 - 已发送的标头” - Troubleshooting “Warning: session_start(): Cannot send session cache limiter - headers already sent” 警告:session_start():无法发送会话缓存限制器 - 已发送的标头 - Warning: session_start(): Cannot send session cache limiter - headers already sent session_start():无法发送会话缓存限制器-我的服务器中已发送的标头 - session_start(): Cannot send session cache limiter - headers already sent in my server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM