( ! ) Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in D:\www\up\php\php_02.php on line 24
Call Stack
#TimeMemoryFunctionLocation
10.0000354752{main}( )...\php_02.php:0

( ! ) Warning: include(http://pub.houheaven.com/Nav02/Nav_deep2.htm): failed to open stream: no suitable wrapper could be found in D:\www\up\php\php_02.php on line 24
Call Stack
#TimeMemoryFunctionLocation
10.0000354752{main}( )...\php_02.php:0

( ! ) Warning: include(): Failed opening 'http://pub.houheaven.com/Nav02/Nav_deep2.htm' for inclusion (include_path='.;C:\php\pear') in D:\www\up\php\php_02.php on line 24
Call Stack
#TimeMemoryFunctionLocation
10.0000354752{main}( )...\php_02.php:0

PHP5 Cookie 用法:setcookie(Name,Value,Expire,Path,Domain,Secure);

一般情况下,我们设置Cookie只会设置它的前三个属性:Name、Value、Expire,即分别是Cookie的属性名、属性值、过期时间,设置的这样的Cookie它的作用范围是有限的,它的属性值只能在本网页、同一父目录下的兄弟网页、子目录下的所有网页中传递,而再往上一级目录中的网页是无法读取此Cookie值的。


比如,在你的服务器主机上的网站根目录是webroot,网站文件结构如下:

  • index.php
  • aaa/a1.php
  • aaa/a2.php
  • aaa/aaa2/a3.php
  • bbb/b1.php

①. 如果 index.php 设置了Cookie,则全部网页都能读取Cookie值,因为全在其作用范围内。

②. 如果 b1.php 设置了Cookie,则 b1.php 能够读取Cookie值,其余都不能读取到,因为跨目录。

③. 如果 a3.php 设置了Cookie,则 a3.php 能够读取Cookie值,其余都不能读取到,因为跨目录。

④. 如果 a1.php 设置了Cookie,则 a1.php 、a2.php、a3.php 能够读取Cookie值,因为在其作用范围内,index.php、b1.php 不能读取,因为跨目录。


以上出现的Cookie无法正常传递的原因就是 跨目录、跨网页,其实这也不是PHP的Bug,只是你自己在使用 setcookie() 时设置不当所导致的,因为你并没有为其设置 Path 属性来拓展它的作用范围。

解决方法:

为 setcookie() 设置Path属性,并将 Path 属性值设置为 "/"。

setcookie("url","www.houheaven.com",Time()+3600,"/");

注意:Cookie的设置与清除需要一致,设置了什么属性清除时就得再次赋值,这样才能正常生效。

显示框架
显示框架
显示框架
显示框架