我的代码在我的其他项目上工作正常,但在这个项目中,我在登录时收到此错误

时间:2018-04-01 06:52:44

标签: phpmyadmin

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 52
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 52
Warning: Cannot modify header information - headers already sent by (output started at D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\header.php:7) in D:\Inetpub\vhosts\axiszone.in\miptv.axiszone.in\admin\index.php on line 54

1 个答案:

答案 0 :(得分:0)

您只是在不发布代码的情况下发布错误。您期望从stackoverflow获得正确的响应。你认为Stackoverflow是能够解释人们心中存在的精神吗?

您发送的错误可能存在的问题可能是您在很多地方初始化php会话。

1。)检查以确保您没有在该页面上的多个位置初始化会话( session_start(); )。

2。)您正在接收已发送的错误数据包,因为您正在尝试在php页面中发送html。可以通过在页面开头设置 ob_start()并在页面底部设置 ob_flush_end()来删除此错误。

当然您也可以使用 error_reporting(0)函数

禁用错误通知

所以您的代码可能看起来像

<?php
error_reporting(0);
ob_start();
/* You can initialized  here and ensure you did not set it any other place on the same pge"/
session_start();

// your page content here







//at the bottom of page
ob_flush_end();
?>

错误将消失

根据您的帖子更新的答案在这里,并且有效。

<html>

<head><body>
<form action="log.php" method="post">

name: <input type="" name="username"><br>
password: <input type="" name="password"><br>

 <input type="submit" name="login" value="login"><br>
</form>
</body>
</html>


<?php 
error_reporting(0);
ob_start();


if (isset($_POST['login'])) { 
session_start();
$con = mysqli_connect("localhost","root","","myfriend_db");

$username=$_POST['username']; 
$password=$_POST['password']; 
$result=mysqli_query($con,"select * from users where username='$username' and password='$password'")or die (mysqli_error()); 
$count=mysqli_num_rows($result);
 $row=mysqli_fetch_array($result);
 if ($count > 0) { 

 $_SESSION['id']=$row['id']; 
header('location:admin.php');
 }else{ 
echo "error: username and password not found";
 echo "<br> <div class='alert alert-error'> <button type='button' class='close' data-dismiss='alert'>&times;</button>";


}
}else{

echo "login value not set in the form";
}

ob_flush_end();
?>

请记住,您的代码容易受到各种攻击 Sql注入,html注入,xss攻击,会话固定和劫持,缓冲区溢出,输入攻击等等....尝试在生产中部署之前实现所有这些安全性。