好的,错误已修复,但现在登录时会让我到错页面
我正在用虚拟货币开店。 我正在使用000webhost来托管它。但是当我尝试运行它时,它给了我这些错误:
Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/a7020156/public_html/checklogin.php:2) in /home/a7020156/public_html/checklogin.php on line 41
Warning: Cannot modify header information - headers already sent by (output started at /home/a7020156/public_html/checklogin.php:2) in /home/a7020156/public_html/checklogin.php on line 47
我的错误页面代码:(详细信息已删除)
<?php
ob_end_flush();
define('DEBUG', TRUE);
ob_start();
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$nav = $_GET['nav_to'];
$nav_to = (string)$nav;
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$mypass = md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypass'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypass and redirect to file "login_success.php"
$sql="SELECT credits FROM $tbl_name WHERE username='$myusername' and password='$mypass'";
$creds=mysql_query($sql);
$row = mysql_fetch_row($creds);
session_register("myusername");
session_register("mypass");
if(!empty($nav_to)){
header("location:$nav_to");
}
if(empty($nav_to)){
header("location:login_success.php?name=$myusername");
setcookie("valid", "true", time()+3600);
setcookie("creds", "$row[0]", time()+3600);
}
}else {
echo "Wrong Username or Password";
echo "<p><a href='main_login.php'>Back</a></p>";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
</body>
</html>
用于登录的页面:
<html>
<head>
<title>Please login</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php" style="color:#B3B3B3;">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" class="field" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" class="field" id="mypassword"></td>
</tr>
<tr>
<td><a href="insert.php">Register</a></td>
<td><input type="submit" name="Submit" class="but" value="Login"></td>
<td><a href="contact.php">Forgot pass?</a></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
我正试图导航到shop.php
我做错了什么? 这个地址是http://mackscript.netii.net 在此先感谢// Mackan90096
答案 0 :(得分:3)
如果您已将任何内容推送到输出,则无法启动会话。
删除此行:
ob_end_flush();