|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
不断巩固,摸透大部分PHP常用函数,并可理解OOP,MYSQL优化,以及模板 </p> 人人都晓得SESSION是不成以跨域的,也就是说: A.WEMVC.COM这个域的可履行文件不成以会见到B.WEMVC.COM的SESSION,这个是SESSION的特征,一样也是出于平安角度才如许的.
在普通情形下,一个网站只要一个域名,然而也有些网站架构是由多个子域名组建的.所以就需求SESSION可以跨子域被会见到,如许才可以完成用户的跨域登录.就是说客户在A下登录的,一样B也同时登录了,不需求用户再次登录,同时也完成了参数的跨域传递.固然不成跨域的SESSION自己已可以匡助咱们做良多工作了,那末跨域后的SESSION呢.读到这里是不是很冲动人心,固然你也多是正在为SESSION跨域而忧愁而找到这篇文章的,一样也庆祝你.咱们长话断说了,入手下手咱们明天的课程:COOKIE与SESSION联用完成SESSION跨域.
起首让咱们再从头复习下PHP中的COOKIE和SESSION:
COOKIE:
界说:
cookie 经常使用于辨认用户。cookie 是办事器留在用户盘算机中的小文件。每当不异的盘算机经由过程阅读器恳求页面时,它同时会发送 cookie。经由过程 PHP,您可以创立并取回 cookie 的值。PS:个中文名叫”曲奇”.
在PHP顶用setCookie函数来设置COOKIE,该函数一共有7个参数(在此我要向已经我面试过的一名同仁报歉,事先我把谜底说成了6个,SORRY~,同时我也提示宽大作家尽快更新本人的文章,在PHP5.2.0版本中已增添为7个参数.),这7个参数分离为 string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] .
name The name of the cookie. 划定 cookie 的称号。
value The value of the cookie. This value is stored on the clients computer; do not store sensitive information. Assuming the name is ‘cookiename’, this value is retrieved through $_COOKIE['cookiename'] 划定 cookie 的值。
expire The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you’ll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).划定 cookie 的无效期。
Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally.
expire is compared to the client’s time which can differ from server’s time. path The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain . If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.划定 cookie 的办事器途径。
domain The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you’d set it to ‘.example.com’. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the |
|