问题:
===================================
file:t.cookie.php 
<?php 
$value   =   'something   from   somewhere'; setcookie("TestCookie",   $value,   time()+3600,   "/~rasmus/",   ".laoxi.com",   1); 
?> 
file:tfcookie.php 
<?php 
file_get_contents("http://laoxi.com/cookie/t.cookie.php"); 
?> 
file:tcookie.php 
<?php 
print_R($_COOKIE); 
?> 
运行程序tfcookie.php,然后运行tcookie.php,却没有注册任何Cookie信息,为什么??
回复:
===========================既然在同一网站,应该用include或者require之类的函数来包括文件。file_get_contents貌似只取得内容。

解决方案 »

  1.   

    file_get_contents("http://laoxi.com/cookie/t.cookie.php");  ==>$result = file_get_contents("http://laoxi.com/cookie/t.cookie.txt");//注意文件类型改成文本类型
    eval($result);
      

  2.   

    file_get_contents   —   将整个文件读入一个字符串说明
    string   file_get_contents   (   string   $filename   [,   bool   $use_include_path   [,   resource   $context   [,   int   $offset   [,   int   $maxlen   ]]]]   )
    和   file()   一样,只除了   file_get_contents()   把文件读入一个字符串。将在参数   offset   所指定的位置开始读取长度为   maxlen   的内容。如果失败,file_get_contents()   将返回   FALSE。  file_get_contents()   函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。  Note:   如果要打开有特殊字符的   URL   (比如说有空格),就需要使用   urlencode()   进行   URL   编码。  ----------------仅文件,不包含http的cookie处理。---------
    楼主对这里的cookie概念理解有误差。程序的用途,很显然,file_get_contents已经作为一个相对的客户端来使用了,即,运行tfcookie.php的服务器端(称之为s1)模拟一个客户端来向其他服务器(称之为s2,即使它跟s1是同一个服务器)请求数据,此时即使s2向s1投放了cookie,也只能称s1上的cookie是客户端cookie,   而不是服务器端的cookie。服务器端(s1)的cookie只能是其他客户端向服务器端(s1)提交的cookie,   而不是其他服务器(s2)投放在本服务器(s1)的cookie.
      

  3.   

    顶surreyKong的解答
    楼主可以看看这个http://wjjchen.blog.163.com/blog/static/1628722200801144537386/