PHP cookieºÍsessionµÄ·ÖÎö£¨×ª£©
1. PHPµÄCOOKIE
cookie ÊÇÒ»ÖÖÔÚÔ¶³Ìä¯ÀÀÆ÷¶Ë´¢´æÊý¾Ý²¢ÒÔ´ËÀ´¸ú×ÙºÍʶ±ðÓû§µÄ»úÖÆ¡£
PHPÔÚhttpÐÒéµÄÍ·ÐÅÏ¢Àï·¢ËÍcookie, Òò´Ë setcookie() º¯Êý±ØÐëÔÚÆäËüÐÅÏ¢±»Êä³öµ½ä¯ÀÀÆ÷Ç°µ÷Óã¬ÕâºÍ¶Ô header() º¯ÊýµÄÏÞÖÆÀàËÆ¡£
1.1 ÉèÖÃcookie:
¿ÉÒÔÓà setcookie() »ò setrawcookie() º¯ÊýÀ´ÉèÖà cookie¡£Ò²¿ÉÒÔͨ¹ýÏò¿Í»§¶ËÖ±½Ó·¢ËÍhttpÍ·À´ÉèÖÃ.
1.1.1 ʹÓÃsetcookie()º¯ÊýÉèÖÃcookie:
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure [, bool httponly]]]]]] )
name: cookie±äÁ¿Ãû
value: cookie±äÁ¿µÄÖµ
expire: ÓÐЧÆÚ½áÊøµÄʱ¼ä,
path: ÓÐЧĿ¼,
domain: ÓÐЧÓòÃû,¶¥¼¶ÓòΨһ
secure: Èç¹ûֵΪ1,ÔòcookieÖ»ÄÜÔÚhttpsÁ¬½ÓÉÏÓÐЧ,Èç¹ûΪĬÈÏÖµ0,ÔòhttpºÍhttps¶¼¿ÉÒÔ.
Àý×Ó:
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value); /* ¼òµ¥cookieÉèÖÃ */
setcookie("TestCookie", $value, time()+3600); /* ÓÐЧÆÚ1¸öСʱ */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1); /* ÓÐЧĿ¼ /~rasmus,ÓÐЧÓòÃûexample.com¼°ÆäËùÓÐ×ÓÓòÃû */
?>
ÉèÖöà¸öcookie±äÁ¿: setcookie('var[a]','value');ÓÃÊý×éÀ´±íʾ±äÁ¿,µ«ËûµÄϱ겻ÓÃÒýºÅ.ÕâÑù¾Í¿ÉÒÔÓÃ$_COOKIE[‘var’][‘a’]À´¶ÁÈ¡¸ÃCOOKIE±äÁ¿.
1.1.2. ʹÓÃheader()ÉèÖÃcookie;
header("Set-Cookie: name=$value[;path=$path[;domain=xxx.com[;]]");
ºóÃæµÄ²ÎÊýºÍÉÏÃæÁгösetcookieº¯ÊýµÄ²ÎÊýÒ»Ñù.
±ÈÈç:
$value = 'something from somewhere';
header("Set-Cook
Ïà¹ØÎĵµ£º
Í·²¿µ÷ÓÃ
<?
require('conn.php');
$sql1="select id from news";
$query1=mysql_query($sql1,$conn);
$sun_num=mysql_num_rows($query1);
$gs=20;
$page_num=ceil($sun_num/$gs);
include("../subpage.php");
//´«¹ýÀ´µÄÒ³Êý²ÎÊý
$PB_page=$_GET['PB_page'];
if ($PB_page==1 or empty($PB_page)){
$ ......
×÷Õß: laruence(http://www.laruence.com
)
±¾ÎĵØÖ·: http://www.laruence.com/2010/05/04/1450.html
תÔØÇë×¢Ã÷³ö´¦
ÔÚ´óÐ͵ÄWebÏîÄ¿ÖÐ, include_pathÊÇÒ»¸öÄ£¿é»¯Éè¼ÆµÄ¸ù±¾Öеĸù±¾(µ±È»,ÏÖÔÚÒ²Óкܶà»ùÓÚautoloadµÄÉè¼Æ,
Õâ¸ö²»Ó°Ïì±¾ÎĵÄ̽ÌÖ), µ«ÊÇÕýÊÇÒòΪinclude_path, ¾³£»áÈÃÎÒÃÇÓöµ½Ò»Ð©ÒòΪûÓÐÕÒµ½Õ ......
¡¡sessionÊÇÍøÕ¾±£´æÓû§ÐÅÏ¢µÄÒ»ÖÖÊֶΣ¬Ó¦ÓÃÏ൱¹ã·º¡£ÀýÈçµÚÎå½ìÅÅÐаñ¾ÍʹÓÃÁËsession¡£¾¹ý¶ÔµÚÎå½ìÅÅÐаñµÄÐ޸ģ¬ÎÒ×ܽáÁËÒ»ÏÂphpÖÐsessionµÄÓ÷¨¡£
£¨Ò»£©¿ªÊ¼session
¡¡¡¡ÔÚÿһ´ÎʹÓÃsession֮ǰ£¬¶¼Òª¼ÓÉÏÕâÒ»¾ä£º“session_start();”¡£¹ËÃû˼Ò壬Õâ¸öº¯ÊýµÄ×÷ÓþÍÊÇ¿ªÊ¼Ê¹ÓÃsession¡£
£¨¶þ£©×¢ ......
ÔÀí£º¸ù¾Ý²»Í¬µÄIPͳ¼Æ³öµ±Ç°ÓжàÉÙÈËÔÚÏß¡£
ʵÏÖ·½Ê½£º¿ÉÒÔÓÃÊý¾Ý¿â£¬Ò²¿ÉÒÔÓÃÎı¾¡£
ÎÒÕâÀïÓÃÁËÎı¾ÊµÏÖ¡£
<?php
/**
*@ Date 2010.04.07
*@ Author »ªÏÄÖ®ÐÇ PHP100.com
*@ Blog & ......