我确实知道这已经发布过很多次了,但我仍然遇到问题。
当我登录我的网站时,我希望开始一个会话。当我开始会话时,我收到此错误。
警告:session_start() [function.session-start]:无法发送会话 cookie - 标头已由 /home1/gretar/public_html/login.php 中的(输出开始于 /home1/gretar/public_html/login.php:27)发送在第 30 行
警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /home1/gretar/public_html/login.php:27)在 /home1/gretar/public_html/login.php在第 30 行
所以这就是我的代码的样子
<?php
include('mysql_connect.php');
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(md5($_POST['password']));
$verified = mysql_real_escape_string($_POST['verified']);
$query = "SELECT * FROM members WHERE username='$username' AND password='$password'";
mysql_query("SELECT verified FROM members WHERE username='$username'");
$sql = mysql_query("SELECT verified FROM members WHERE username='$username'");
while($row = mysql_fetch_array($sql)){
$verified = $row["verified"];
};
$result = mysql_query($query);
$query_rows = mysql_num_rows($result);
if($query_rows > 0) {
if($verified == 1) {
echo("User Verified");
} else if($verified == 0) {
echo("User not verified");
}
echo ("Succesfull login!");
session_start();
$_SESSION['login'] = "1";
}else{
echo("Bad login!");
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post"/>
Username: <input type="text" name="username"/><br>
Password <input type="password" name="password"/> <br>
<input type ="submit" value="Login!"/>
</body>
</html>
这个答案真的帮助了我。