שלום.
בניתי טופס התחברות.
הרעיון הוא כזה:
אם הכפתור נלחץ - המערכת תבדוק אם הפרטים נכונים, אם כן תחבר את המשתמש, אם לא (else) מציג לו את הטופס עם שגיאה.
אם הכפתור לא נשלח - מציג לו את הטופס בלבד.
כשאני מצליח להתחבר..אני מקבל שגיאה:
Cannot modify header information - headers already sent by
אני מקבל פעמיים, השורות שמצויינות הן השורות של הצבת העוגיות.
זה הקוד המלא:
PHP קוד:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("phpmyadmin");
$user_name = mysql_real_escape_string(htmlspecialchars($_POST['user_name']));
$password = mysql_real_escape_string(htmlspecialchars(md5($_POST['password'])));
$query = mysql_query("SELECT * FROM users WHERE user_name='$user_name'");
$row=mysql_fetch_array($query);
$row_password=$row['password'];
$row_user_name=$row['user_name'];
$password_cookie=$row['password'];
$user_name_cookie=$row['user_name'];
if (isset($_POST['submit']))
{
if ($row_password==$password && $row_user_name==$user_name)
{
setcookie("username", $user_name, time()+60000);
setcookie("id", $id_cookie, time()+60000);
echo '<meta http-equiv="refresh" content="0;url=index.php" />';
}
else
{
echo '
<div id="top_menu">
<span class="menu_class">
<a href="sign_in.php">Login</a>
<a href="sign_up.php">Register</a>
</span>
</div>
<h1>Login to your account...</h1>
<div id="register_message"><p class="failed">Login Fail!</p>
<span class="failed">Please check your deatiles and try again.</span></div>
<div id="form">
<form action="" method="POST">
<table id="registertable" cellpadding="10" border="0">
<tr>
<td align="left">
<span class="field">Username:</span>
</td>
<td align="left">
<input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
</td>
</tr>
<tr>
<td align="left">
<span class="field">Password:</span>
</td>
<td align="left">
<input type="Password" name="password" id="password" dir="ltr" value="" style="width:200px;" maxlength="15">
</td>
<tr>
<td align="right"></td>
<td align="center">
<label> </label><input type="submit" name="submit" value="" id="submit" />
</td>
</tr>
</table>
</form>
</div>
<div id="copyrights">
© All rights reserved.
</div>
}
';
}
}
else
{
echo '
<div id="top_menu">
<span class="menu_class">
<a href="sign_in.php">Login</a>
<a href="sign_up.php">Register</a>
</span>
</div>
<h1>Login to your account...</h1>
<div id="form">
<form action="" method="POST">
<table id="registertable" cellpadding="10" border="0">
<tr>
<td align="left">
<span class="field">Username:</span>
</td>
<td align="left">
<input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
</td>
</tr>
<tr>
<td align="left">
<span class="field">Password:</span>
</td>
<td align="left">
<input type="Password" name="password" id="password" dir="ltr" value="" style="width:200px;" maxlength="15">
</td>
<tr>
<td align="right"></td>
<td align="center">
<label> </label><input type="submit" name="submit" value="" id="submit" />
</td>
</tr>
</table>
</form>
</div>
<div id="copyrights">
© All rights reserved.
</div>
';
}
?>
לא כתבתי שום דבר לפני כן, הדף ריק לגמרי..מה נחשב "header"? אולי הלולאה שם?
תודה רבה לכם
