phpÔÚ¿Í»§¶Ë½ûÓÃcookieʱÈÃsession²»Ê§Ð§µÄ½â¾ö·½·¨
cookie¹ÌÈ»ºÃ£¬²»¹ýÓÐЩ¿Í»§¶Ëä¯ÀÀÆ÷»á½ûÓÃcookie£¬Õâ¾Í»áµ¼ÖÂÄãËùÒÀÀµcookiesµÄ³ÌÐò»áʧЧ»ò³ö´í£¬ÄÇôÈôÕæ³öÏÖÓû§¹Ø±ÕcookiesµÄÇé¿ö£¬PHPÓ¦¸ÃÈçºÎÔÙ´ÎʹÓÃsession£¿·½·¨»¹ÊÇÓеġ£
1¡¢ÉèÖÃphp.iniµÄsession.use_trans_sid = 1»òÕß´ò¿ªenable-trans-sidÑ¡ÏÈÃPHP×Ô¶¯¿çÒ³´«µÝsession id¡£
2¡¢ÊÖ¶¯Í¨¹ýURL´«Öµ¡¢Òþ²Ø±íµ¥´«µÝsession id¡£
3¡¢ÓÃÎļþ¡¢Êý¾Ý¿âµÈÐÎʽ±£´æsession_id,ÔÚ¿çÒ³¹ý³ÌÖÐÊÖ¶¯µ÷Óá£
;¾¶1¾ÙÀý˵Ã÷£º
s1.php
<?php
session_start();
$_SESSION[¡¯var1¡¯]="Ô´Âë°®ºÃÕß";
$url="<a href=".""s2.php">ÏÂÒ»Ò³</a>";
echo $url;
?>
s2.php
<?php
session_start();
echo "´«µÝµÄsession±äÁ¿var1µÄֵΪ£º".$_SESSION[¡¯var1¡¯];
?>
ÔËÐÐÒÔÉÏ´úÂ룬ÔÚ¿Í»§¶ËcookieÕý³£µÄÇé¿öÏ£¬Ó¦¸Ã¿ÉÒÔÔڵõ½½á¹û¡°Ô´Âë°®ºÃÕß¡±¡£
Èô´Ëʱ¹Ø±ÕÁË¿Í»§¶ËµÄcookie£¬¹À¼Æ¾ÍµÃ²»µ½½á¹ûÁË£¬Õâʱ¿ÉÉèÖÃphp.iniÖеÄsession.use_trans_sid = 1»òÕß±àÒëʱ´ò¿ª--enable-trans-sidÑ¡Ï£¬´ËʱÓÖ¿ÉÖØеõ½½á¹û¡°Ô´Âë°®ºÃÕß¡±
;¾¶2¾ÙÀý˵Ã÷£º
s1.php
<?php session_start(); $_SESSION[¡¯var1¡¯]="Ô´Âë°®ºÃÕß"; $sn = session_id(); $url="<a href=".""s2.php?s=".$sn."">ÏÂÒ»Ò³</a>"; echo $url; ?>
s2.php
<?php
session_id($_GET[¡¯s¡¯]);
session_start();
echo "´«µÝµÄsession±äÁ¿var1µÄֵΪ£º".$_SESSION[¡¯var1¡¯];
?>
Òþ²Ø±íµ¥µÄ·½·¨»ù±¾ÔÀíͬÉÏ¡£
;¾¶3¾ÙÀý˵Ã÷£ºlogin.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> ÇëµÇ¼£º <form name="login" method="post" action="mylogin1.php"> Óû§Ãû:<input type="text" name="name"><br> ¿Ú¡¡Áî:<input type="password" name="pass"><br> <input type="submit" value="µÇ¼"> </form> </body> </html>
mylogin1.php
<?php
$name=$_POST[¡¯name¡¯];
$pass=$_POST[¡¯pass¡¯];
if(!$name || !$pass) {
echo "Óû§Ãû»òÃÜÂëΪ¿Õ£¬Çë<a href="login.html">ÖØеǼ</a>";
die();
}
if (!($name=="youngong" && $pass=="123") {
echo "Óû§Ãû»òÃÜÂë²»ÕýÈ·£¬Çë<a href="login.html">ÖØеǼ</a>";
die();
}
//×¢²áÓû§
ob_start();
session_start();
$_SESSION[¡¯user¡¯]= $name;
$psid=session_id();
$fp=fopen("e:\tmp\phpsid.txt","w+";
fwrite($fp,$psid);
fclose($fp);
//Éí·ÝÑéÖ¤³É¹¦£¬½øÐÐÏà¹Ø²Ù×÷
echo "ÒѵǼ<br>";
echo "<a href="mylogin2.php">ÏÂÒ»Ò³</a>";
?>
mylogin2.php
<?php
$fp=fopen("e:\tmp\phpsid.txt","r";
$sid=fread($fp,1024);
fclose($fp);
session_id($sid);
session_start();
if(isset($_SESSION[¡¯user¡¯]) && $_SESSION[¡¯user¡¯]="laogong" {
echo "ÒѵǼ!";
}
else {
//³É¹¦µÇ¼½øÐÐÏà¹Ø²Ù×÷
echo "δµÇ¼£¬ÎÞȨ·ÃÎÊ";
echo "Çë<a href="login.html">µÇ¼</a>ºóä¯ÀÀ";
die();
}
?>
Çë¹Ø±ÕcookieÔÙ²âÊÔ£¬Óû§Ãû£ºtest ÃÜÂ룺123 ÕâÊÇͨ¹ýÎļþ±£´æsession idµÄ£¬ÎļþÊÇ£º/tmp/phpsessid.txt¡£ÖÁÓÚÓÃÊý¾Ý¿âµÄ·½·¨£¬¾Í²»¾ÙÀý×ÓÁË£¬ÓëÎļþµÄ²Ù×÷·½·¨ÀàËÆ¡£ÒÔÉÏ·½·¨ÓÐÒ»¸ö¹²Í¬µã£¬¾ÍÊÇÔÚǰһҳȡµÃsession id£¬Ïë°ì·¨´«µÝµ½ÏÂÒ»Ò³£¬ÔÚÏÂÒ»Ò³µÄsession_start();֮ǰ¼Ó´úÂësession_id(´«¹ýÀ´µÄsession id)¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ