ช่วยดูโค้ด Login ให้หน่อยคับ อยากให้เมื่อ LogIn เข้ามาแล้วให้แสดงชื่อ User ในหน้าที่ Link ถัดไปคับทำเท่าไรก้อทำไม่ได้ช่วยดูทีคับ
อยากให้เมื่อ LogIn เข้ามาแล้วให้แสดงชื่อ User ในหน้าที่ Link ถัดไปคับทำเท่าไรก้อทำไม่ได้ช่วยดูทีคับ
นี้โค้ด form LogIn คับ
<form action="check.php" method="post" name="form1" id="form1" onsubmit="MM_validateForm('UserID','','R','Password','','R');return document.MM_returnValue">
<table width="480" height="289" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7" bgcolor="#0099FF"><div align="center"><span class="style19">LogIn</span></div></td>
</tr>
<tr>
<td width="190"><div align="right"><span class="style17">UserID : </span></div></td>
<td width="288" height="50" colspan="6"><input name="UserID" type="text" class="inputbox autowidth" id="UserID" tabindex="1" onblur="MM_validateForm('UserID','','R');return document.MM_returnValue" value="" size="25" /></td>
</tr>
<tr>
<td><div align="right"><span class="style17">Password :</span></div></td>
<td height="50" colspan="6"><input name="Password" type="password" class="inputbox autowidth" id="Password" tabindex="2" onchange="MM_validateForm('UserID','','R','Password','','R');return document.MM_returnValue" size="25" /></td>
</tr>
<tr>
<td> </td>
<td colspan="6"><input name="chk" type="checkbox" id="chk" value="on" />
<span class="style1 style20">เข้าระบบอัตโนมัตspan></td>
</tr>
<tr>
<td> </td>
<td colspan="6"><input type="checkbox" name="viewonline22" id="viewonline22" tabindex="5" />
<span class="style1 style20">ซ่อนตัว </span></td>
</tr>
<tr>
<td> </td>
<td colspan="6"><input name="Submit" type="submit" class="button1" id="Submit" tabindex="6" value=" เข้าสู่ระบบ " /></td>
</tr>
</table>
</form>
นี่โค้ดรับค่าจากฟอร์มคับ
<?
ob_start();
$host = "localhost";
$db_username = "root";
$db_password = "123456";
$dbname = "datauser";
mysql_connect($host, $db_username, $db_password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
$sql = "select * from user where UserID='$UserID' and Password='$Password'";
$dbquery = mysql_db_query($dbname, $sql);
$num_rows = mysql_num_rows($dbquery);
if($num_rows == 1) {
if($chk == "on") {
ob_start();
setcookie("UserID",$UserID,time()+3600*24*356);
setcookie("Password",$Password,time()+3600*24*356);
$_SESSION['time'] = time();
header("location:HOME.php");
} else {
header("location:HOME.php");
}
} else {
header("location:Cannot.html");
}
?>
แล้วก้อนี่โค้ดที่รับค่า LogIn มาแล้วให้แสดงในหน้านี้คับ
<?
if($chk == "on") {
ob_start();
echo "<strong>คุณ</strong>$_COOKIE[UserID]<br><p><p>";
echo "<strong>You are LOGIN</strong><p>";
echo date('D d M Y H:i:s', $_SESSION['time']);
echo "<br><strong><a href=delcookie.php>LogOut</a></strong></br>";
}
else
{
echo '<strong><p class="style22 คุณยังไม่ได้เข้าสู่ระบบ</strong><p>';
echo '<strong><a href="OutPage.html">Log In</a></strong>';
}
?>Tag : - - - -
Date :
2009-05-28 00:16:07
By :
น้องบี
View :
1273
Reply :
2
หน้าที่รับค่ายังไม่ได้ประกาศ session_start เลยครับ
Date :
2009-05-28 02:43:21
By :
kanchen
ดูตามนี้แล้วกันครับ ค่อนข้างชัดเจนนะ
https://www.thaicreate.com/php/php-cookie.html
Date :
2009-05-29 09:25:28
By :
jeabz
Load balance : Server 01