|
 |
|
โค้ดเต็มๆ เกี่ยวกับ cookie เปลี่ยนจากซีซั่นเป็นคุ๊กกี้แทนครับ เวลาเปิดหน้าอื่นที่ไม่ใช่หน้า index.php |
|
 |
|
|
 |
 |
|
<?
//index.php
session_start();
include "member/config.inc.php";
$txtuser = $_POST['txtuser'];
$txtpass = $_POST['txtpass'];
$db = mysql_connect($host,$username,$password) or die ("ไม่สามารถติดต่อ database ได้ในขณะนี้");
$sql = "select * from member where users = '$txtuser' and passwd = '$txtpass' ";
$result = mysql_db_query($dbname,$sql) or die ("ไม่สามารถสั่งให้ database ทำงานได้ในขณะนี้");
$NRow = mysql_num_rows($result);
$arr = mysql_fetch_row( $result );
if ($NRow>0){
include ("member/login.php");
}else{
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>";
}
?>
<?
// Login.php
setcookie("id", $arr[0], time() + 3600 * 24 * 365);
setcookie("users", $arr[1], time() + 3600 * 24 * 365);
setcookie("passwd", $arr[2], time() + 3600 * 24 * 365);
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>";
?>
<?
//Logout.php
setcookie("id", "");
setcookie("users", "");
setcookie("passwd", "");
echo "You are now logged out! <a href=../index.php>Index</a> or <a href=login.php>Login</a>";
?>
ต้องล็อกอินใหม่ตลอดเวลา
อยากได้เหมือนเว็บนี้อะครับ ไม่ logout อีก10วันมาเปิด User ก็ยังค้างเหมือนเดิม
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-11-27 15:51:52 |
By :
sawet50 |
View :
1901 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
define('_W_ROOT_', "/");
class cookies {
/**
* remove($name) ลบคุกกี้ออกตามชื่อคุกกี้
*/
static public function remove($name) {
if (!empty($name)) {
if ($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "localhost:81") {
$webaddress = false;
} else {
$webaddress = $_SERVER['HTTP_HOST'];
}
setcookie($name, "", time()-63113851.9, _W_ROOT_, $webaddress);
return true;
} else {
return false;
}
}//remove
/**
* write($name,$value,$timeout='0') เขียนคุกกี้
*/
static public function write($name, $value, $timeout='0') {
if (!empty($name) && !empty($value)) {
if ($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "localhost:81") {
$webaddress = false;
} else {
$webaddress = $_SERVER['HTTP_HOST'];
}
setcookie($name, $value, $timeout, _W_ROOT_, $webaddress);
return true;
} else {
return false;
}
}//write
}
ลองเอาไปเล่นดู
cookies::write("name","value",time()+1111);
ลบก็ cookies::remove("name");
|
 |
 |
 |
 |
Date :
2009-11-27 17:03:03 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอรายละเอียดเป็นอีกนิดได้มั้ยครับ งงไก่ตาแตกเลย ผมมือสมัครเล่นง่ะ
|
 |
 |
 |
 |
Date :
2009-11-27 17:27:38 |
By :
sawet50 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวอย่างการใช้ก็มีแค่นั้น เขียนไว้ให้แล้วไง ใช้แค่สั้นๆ ถ้ากำหนดหมดอายุก็
cookies::write("name","value",time()+1111);
ถ้าไม่กำหนดหมดอายุ (หมดเมื่อปิด browser) cookies::write("name","value");
ลบก็ cookies::remove("name");
นอกนั้นก็ไม่มีอะไร เขียนเก็บไว้ไฟล์ไหนสักไฟล์แล้ว include จะยากตรงไหน?
|
 |
 |
 |
 |
Date :
2009-11-27 23:32:03 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูก่อนดีกว่า ติดตรงไหนค่อยถาม
|
 |
 |
 |
 |
Date :
2009-11-27 23:32:35 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
work มั้ย?
|
 |
 |
 |
 |
Date :
2009-11-29 13:25:05 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ว้าววววว อยากได้อยู่พอดีครับ อิอิ ขอบคุณหลายๆ
|
 |
 |
 |
 |
Date :
2009-11-29 13:48:29 |
By :
nerobenz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|