我解决了这个问题谢谢大家我把所有的php代码都移到了页面的第一行(上面的部分)除了用户输入错误的电子邮件我把它留在正文中的情况^_^
我有这个登录代码,它检查用户是否已经是会员。
<?php
$con=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("mydb")or die("error in selecting db");
$email = $_POST['email'];
$password = $_POST['password'];
if( $email && $password)
{
$query = "select * from users where email = '$_POST[email]' and password = '$_POST[password]'";
$result = mysql_query($query, $con);
$num_rows = mysql_num_rows($result);
$record = mysql_fetch_array($result);
if ($num_rows > 0) {
session_start();
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $_POST['password'];
header("Location: home.php");
}
else
{
echo "<h3><br><br><font>Error in Password or email </font><br> <br>
<font>
if you are new plz register here </a> <br></font>";
echo "</h3>";
}
} else{ echo "<h3><br><br> You Enter any thing , Try again<br> <br> ;}
?>
如果用户输入正确的电子邮件和密码,将得到:
警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已在 C:\wamp\www\vwl 中发送(输出开始于 C:\wamp\www\vwl\login.php:122) \login.php 在第 170 行
警告:无法修改标头信息 - 标头已由第 174 行 C:\wamp\www\vwl\login.php 中的(输出开始于 C:\wamp\www\vwl\login.php:122)发送
成功进入时打印welcome的代码是:
<?php
// session_start();
//connect to db
if (isset($_COOKIE["email"]) && isset($_COOKIE["password"])) {
$query = "select * from users where email = '$_COOKIE[email]' and password = '$_COOKIE[password]'";
} else {
$query = "select * from users where email='$_SESSION[email]' and password='$_SESSION[password]'";
}
$result = mysql_query($query, $con);
echo "<table border = 0>";
$record = mysql_fetch_array($result);
if ($record) {
echo "<tr><td>$record[email]</td>
<td>
</td></tr><br><br>";
} else {
header("Location: login.php");
}
echo "</table>";
?>