µ±Ç°Î»ÖãºLinux½Ì³Ì - Php - ÅжϿͻ§¶ËÊÇ·ñ¾ß±¸javascriptºÍCookie¹¦ÄÜ

ÅжϿͻ§¶ËÊÇ·ñ¾ß±¸javascriptºÍCookie¹¦ÄÜ

ÔÚÎÒµÄÕ¾µãÉÏ£¬ÎÒÏëÈ·ÈÏ·ÃÎÊÕßÊÇ·ñ¾ß±¸cookiesºÍJavaScript¹¦ÄÜ¡£Î¬³Ö»á»°×´Ì¬ÔÚÐí¶àÇé¿ö϶¼ºÜ¸´ÔÓ£¬¶øÇÒÒ²Òª¿¼Âǵ½±íµ¥µÄÑéÖ¤¡£ÔÚÎÒµÄÕ¾µãÉÏ£¬ÎÒʹÓÃÁË¿Í»§¶ËJavaScript½øÐÐ±íµ¥ÑéÖ¤£¬ËùÒÔÒªÍê³ÉÑéÖ¤¹¤×÷£¬Óû§µÄä¯ÀÀÆ÷±ØÐëÒª¾ß±¸JavaScript¹¦ÄÜ¡£Í¬Ê±£¬ÎÒ»¹Ê¹ÓÃÁËSession±äÁ¿£¬Õâ¾ÍÐèÒª·ÃÎÊÕßµÄä¯ÀÀÆ÷Ö§³ÖCookies¹¦ÄÜ¡£ÎªÁËÈ·ÈÏÕâЩǰÌáÌõ¼þµÄ´æÔÚ£¬ÎÒʹÓÃÁËÒ»¶ÎСÇɵĴúÂëÀ´¼ì²éÓû§ÊÇ·ñ¾ß±¸JavaScriptºÍCookies¹¦ÄÜ¡£Èç¹ûÓû§²»¾ß±¸Õâ2¸öÌõ¼þ£¬¾Í¾Ü¾øËûÃǵǼÍøÕ¾¡£ÔÚÕâƪÎÄÕÂÀҲ½éÉÜÎÒµÄÕ¾µãµÄµÇ¼ҳÃæ´úÂë¡£

¡¡¡¡¿ªÊ¼£¬Ê¹ÓÃJavaScript´´½¨Ò»¸öCookie¡£È»ºó£¬ÔÙ¼ì²éÕâ¸öcookieÊÇ·ñ´æÔÚ¡£ÒòΪÎÒÃÇʹÓÃJavaScriptÀ´²âÊÔÓû§ÊÇ·ñ´ò¿ªCookies¹¦ÄÜ£¬Èç¹ûËûÃDz»¾ß±¸JavaScript£¬µ«È´¾ß±¸Cookies£¬ÎÒÃǽ«»áµÃµ½ËûÃDz»¾ß±¸Cookies¹¦ÄܵĽá¹û¡£Õâ¸ö½á¹ûÊǺܺõģ¬ÒòΪÎÒÒªÇóÓû§Í¬Ê±¾ß±¸JavaScriptºÍCookies¹¦ÄÜ¡£ÎªÁËÅжÏÓû§ÊÇ·ñ¾ß±¸JavaScript¹¦ÄÜ£¬ÎÒÔÚHTMLÒ³ÃæÉÏ´´½¨ÁËÒ»¸öÒþ²Ø±íµ¥Óò£¬²¢ÇÒÔÚÒ³Ãæµ÷ÓÃʼþ£¨onload£©Öе÷ÓÃÒ»¸öJavaScriptº¯ÊýÀ´¸Ä±äÕâ¸öÒþ²Ø±íµ¥ÓòµÄÊýÖµ¡£ÕâÑù£¬Èç¹û±íµ¥ÓòµÄÊýÖµ¸Ä±äÁË£¬¾Í±íʾJavaScriptÊÇÉúЧµÄ¡£

¡¡¡¡Ê×ÏÈ£¬ÔÚHTMLÒ³ÃæÉÏ·ÅÖÃÒ»¸öÒþ²ØÓò£¬²¢½«Ëü½éÓÚ< form > ... < /form >Ö®¼ä¡£

<FORM>

...

<input type="hidden" name="cookieexists" value="false">

</FORM>

¡¡¡¡Ö»ÒªÕâ¸öÓòµÄÊýÖµÊÇfalseµÄ£¬ÄÇôÎÒÃǾÍÖªµÀÁËÓû§µÄä¯ÀÀÆ÷²»Ö§³ÖJavaScript¡£×¢Ò⣬ĬÈÏÖµÊÇfalse£¬ÎÒÃDZàдµÄJavaScriptº¯Êý½«¸Ä±äËüΪtrue¡£ËùÒÔ£¬Èç¹ûJavaScriptÉúЧ£¬Õâ¸öJavaScriptº¯Êý½«ÔËÐУ¬ÓòµÄÊýÖµ½«±äΪtrue¡£ÔÚHTMLÒ³ÃæµÄBody±ê¼ÇÖУ¬·ÅÖõ÷ÓÃJavaScriptº¯ÊýµÄ´úÂ룬´Ó¶ø¼ì²écookies(cc)£º

< body onload="cc()" >

¡¡¡¡Èç¹ûº¯Êý²»Ö´ÐУ¨ÕâÖÖÇé¿ö½ö½ö·¢ÉúÔÚJavaScript²»ÉúЧʱ£©£¬cc()º¯Êý¾Í²»»á¸Ä±äÒþ²ØÓòµÄÊýÖµ¡£cc()º¯ÊýµÄ´úÂëÏ൱¼òµ¥£¬ÈçÏ£º

<script language="JavaScript">

<!-

function cc()

{

/* check for a cookie */

if (document.cookie == "")

{

¡¡¡¡/* if a cookie is not found - alert user -

¡¡¡¡ change cookieexists field value to false */

¡¡¡¡alert("COOKIES need to be enabled!");

¡¡¡¡/* If the user has Cookies disabled an alert will let him know

¡¡¡¡¡¡¡¡that cookies need to be enabled to log on.*/

¡¡¡¡document.Form1.cookieexists.value ="false"

} else {

/* this sets the value to true and nothing else will happen,

¡¡¡¡ the user will be able to log on*/

¡¡¡¡document.Form1.cookieexists.value ="true"

}

}

/* Set a cookie to be sure that one exists.

Note that this is outside the function*/

document.cookie = 'killme' + escape('nothing')

// -->

</script>

¡¡¡¡×¢Ò⣺ÔÚº¯ÊýÍâµÄJavaScript´úÂëÐн«ÔÚÒ³Ãæµ÷ÈëÇ°Ö´ÐУ¬ËùÒÔ£¬Ò²¾ÍÊÇÔÚcc()º¯ÊýÇ°±»µ÷Óá£Í¨³££¬JavaScript´úÂë¿éÓ¦¸Ã·ÅÔÚHTMLÒ³ÃæµÄHEADÒ»½ÚÖС£

¡¡¡¡ÕâÑù£¬Èç¹ûJavaScriptÉúЧ¶øCookies²»ÉúЧ£¬Óû§½«µÃµ½¡°ÐèÒª´ò¿ªcookies¹¦ÄÜ¡±µÄÐÅÏ¢Ìáʾ¡£Èç¹ûJavaScript²»ÉúЧ£¬¾Í²»»áÏÔʾÈκÎÐÅÏ¢£¬ÕâÖÖÇé¿öÏ£¬ÎÒÃDz»ÄÜÅжÏcookies¹¦ÄÜÊÇ·ñ´ò¿ª¡£µ±±íµ¥Ìύʱ£¬¼ì²éÒþ²ØÓòcookieexist