|
|
|
เกี่ยวกับ session หน้าเดียว ผมทำโค้ดแบบ login และแสดงในหน้าเดียวกัน ไม่ทราบจะตั้งซีซั่นยังไงดีครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
session_start();
include "connect.php";
if (trim($submit)!=""){ // ถ้ามีการกด submit
$sql = "select * from member where users = '$txtuser' and passwd = '$txtpass' ";
$re=mysql_query($sql) or die(error());
$num=mysql_num_rows($re);
if($num>0){
session_start();
session_register('id');
$row=mysql_fetch_array($re);
$_SESSION['id'] = $row['id'];
$_SESSION['users'] = $row['users'];
}else{
echo "password is incorrect";
}
}
if($_SESSION['id'] !=""){ // check SESSION งว่า ล้อกอินรึยัง
echo "Hello ".$_SESSION['users']; // แสดงชื่อ
exit;
}
?>
<form name='form1' method='post' action='' style='margin:0px;'>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='3' colspan='2'></td>
</tr>
<tr>
<td width='24%'><div align='center' class='styleA1'>User: </div></td>
<td width='76%'><input name='txtuser' type='text' id='txtuser' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td><div align='center' class='styleA1'>Pass: </div></td>
<td><input name='txtpass' type='password' id='txtpass' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td> </td>
<td><div align='left'>
<input type='submit' name='Submit' value='ล็อกอิน' onClick='return check()'>
<input type='reset' name='Submit2' value='ยกเลิก'>
</div></td>
</tr>
</table>
</form>
น่าจะประมานนี้นะครับ
สงสัยถามได้ครับ
|
|
|
|
|
Date :
2009-11-26 11:45:42 |
By :
Sek-Artdrinker |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ
|
|
|
|
|
Date :
2009-11-26 12:41:06 |
By :
sawet50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($_SESSION['users'] ==""){ // check SESSION ว่า ล็อกอินรึยัง
=============
ฟอร์ม
echo "<form name='form1' method='post' action='' style='margin:0px;'>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='3' colspan='2'></td>
</tr>
<tr>
<td width='24%'><div align='center' class='styleA1'>User: </div></td>
<td width='76%'><input name='txtuser' type='text' id='txtuser' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td><div align='center' class='styleA1'>Pass: </div></td>
<td><input name='txtpass' type='password' id='txtpass' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td> </td>
<td><div align='left'>
<input type='submit' name='Submit' value='ล็อกอิน' onClick='return check()'>
<input type='reset' name='Submit2' value='ยกเลิก'>
</div></td>
</tr>
</table>
</form>";
==============
แสดงผล
}else{
echo "<center><table width='100' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='5'></td>
</tr>
<tr>
<td><img src='../member/img/nopic.jpg' width='120' height='120'></td>
</tr>
<tr>
<td height='5'></td>
</tr>
</table>
<span class='styleA1'>$arr[4]</span><br>
<a href='../member/edit.php' target='_parent'>แก้ไขข้อมูล</a> <a href='../member/logout.php' target='_parent' class='styleLink'>ออกระบบ</a>
</center>";
---------------------------------------
if($_SESSION['users'] ==""){ // check SESSION ว่า ล็อกอินรึยัง
ช่วยดูคำสั่งนี้ให้หน่อยครับ มันข้ามฟอร์ม ไปแสดงผลเลย กด Logout ทำลายซีซั่นก็เหมือนเดิม
|
|
|
|
|
Date :
2009-11-26 18:26:50 |
By :
sawet50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logout อย่างประมานนี้รึปล่าวครับ
Code (PHP)
session_start();
session_destroy();
$_SESSION['users']="";
|
|
|
|
|
Date :
2009-11-26 18:40:11 |
By :
Sek-Artdrinker |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?
session_start();
unset($_SESSION["id"]);
unset($_SESSION["users"]);
session_destroy();
echo "You are now logged out! <a href=../index.php>Index</a> or <a href=login.php>Login</a>";
?>
นี่อ่ะครับ ลองเปลี่ยนล็อกเอ๊าท์แบบพี่แล้วก็ไม่ได้ คิดว่าเงื่อนไข if ที่ว่าอ่ะครับ มันข้ามฟอร์ม
|
|
|
|
|
Date :
2009-11-26 18:45:45 |
By :
sawet50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?
session_start();
include "member/config.inc.php";
if (trim($submit)!=""){ // ถ้ามีการกด submit
$sql = "select * from member where users = '$txtuser' and passwd = '$txtpass' ";
$re=mysql_query($sql) or die(error());
$num=mysql_num_rows($re);
if($num>0){
session_start();
session_register('id');
$row=mysql_fetch_array($re);
$_SESSION['id'] = $row['id'];
$_SESSION['users'] = $row['users'];
}else{
echo "password is incorrect";
}
}
if($_SESSION['id'] !=""){ // check SESSION งว่า ล้อกอินรึยัง
=============================================================
แสดงผล
echo "<center><table width='100' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='5'></td>
</tr>
<tr>
<td><img src='../member/img/nopic.jpg' width='120' height='120'></td>
</tr>
<tr>
<td height='5'></td>
</tr>
</table>
<span class='styleA1'>$arr[4]</span><br>
<a href='../member/edit.php' target='_parent'>แก้ไขข้อมูล</a> <a href='../member/logout.php' target='_parent' class='styleLink'>ออกระบบ</a>
</center>";
$userchat = $arr[4];
exit;
}
?>
=============================================
ฟอร์ม
<form name='form1' method='post' action='' style='margin:0px;'>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='3' colspan='2'></td>
</tr>
<tr>
<td width='24%'><div align='center' class='styleA1'>User: </div></td>
<td width='76%'><input name='txtuser' type='text' id='txtuser' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td><div align='center' class='styleA1'>Pass: </div></td>
<td><input name='txtpass' type='password' id='txtpass' style='width:115px' autocomplete='off'></td>
</tr>
<tr>
<td height='2' colspan='2'></td>
</tr>
<tr>
<td> </td>
<td><div align='left'>
<input type='submit' name='Submit' value='ล็อกอิน' onClick='return check()'>
<input type='reset' name='Submit2' value='ยกเลิก'>
</div></td>
</tr>
</table>
</form>
=========================================
ถ้าเอาโค้ดพี่ใส่เข้าไปแบบไม่แก้อะไรเลย ส่วนแสดงผล hidden หายไป มีแต่ฟอร์มแทนครับ
|
|
|
|
|
Date :
2009-11-26 19:18:53 |
By :
sawet50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|