The following example lists the interaction scenarios in several cases and the Interaction methods between JS and php. To avoid further cookie problems. Setcookie. phpViewCodegetcookie. phpViewCode Summary: php uses its own function to read php cookies. There is no obstacle and no decoding is required. Js uses the cookie. js method to read the js cooki
The following example lists the interaction scenarios in several cases and the Interaction methods between JS and php. To avoid further cookie problems. Setcookie. php View Code getcookie. php View Code Summary: php uses its own function to read php cookies. There is no obstacle and no decoding is required. Js uses the cookie. js method to read the js cooki
The following example lists the interaction scenarios in several cases and the Interaction methods between JS and php. To avoid further cookie problems.
Setcookie. php
View Code
Getcookie. php
View Code
Summary:
- Php uses its own functions to read php cookies. There is no obstacle and no decoding is required.
- Js uses the cookie. js method to read js cookies. There is no obstacle and no decoding is required.
- Js reads php Chinese cookies and requires "decodeURIComponent (escape (php_cn_ck)" function processing.
- Php needs to perform the "unescape ()" function to read the Chinese cookies of js.
Cookie. js
Var Cookies = {};/***** set Cookies */Cookies. set = function (name, value) {var argv = arguments; var argc = arguments. length; var expires = (argc> 2 )? Argv [2]: null; if (expires! = Null) {var exp = new Date (); exp. setTime (exp. getTime () + 8*3600 + expires);} alert (exp. toGMTString (); var path = (argc> 3 )? Argv [3]: '/'; var domain = (argc> 4 )? Argv [4]: null; var secure = (argc> 5 )? Argv [5]: false; document. cookie = name + "=" + escape (value) + (expires = null )? "": ("; Expires =" + exp. toGMTString () + (path = null )? "": ("; Path =" + path) + (domain = null )? "": ("; Domain =" + domain) + (secure = true )? "; Secure": "") ;};/***** read Cookies */Cookies. get = function (name) {var arg = name + "="; var alen = arg. length; var clen = document. cookie. length; var I = 0; var j = 0; while (I <clen) {j = I + alen; if (document. cookie. substring (I, j) = arg) return Cookies. getCookieVal (j); I = document. cookie. indexOf ("", I) + 1; if (I = 0) break;} return null ;};/*** clear Cookies */Cookies. clear = function (name) {if (Cookies. get (name) {var expdate = new Date (); expdate. setTime (expdate. getTime ()-(86400*1000*1); Cookies. set (name, "", expdate) ;}}; Cookies. getCookieVal = function (offset) {var endstr = document. cookie. indexOf (";", offset); if (endstr =-1) {endstr = document. cookie. length;} return unescape (document. cookie. substring (offset, endstr ));};
4 function. php
View Code
Bytes