在tcp/ip入门经典知道资源流是一层一层的,现在只讨论http那一层的上下文(header那些):
<?php $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en " . "Cookie: foo=bar " ) ); $context = stream_context_create($opts); /* Sends an http request to www.example.com with additional headers shown above */ $fp = fopen('http://localhost/a.php', 'r', false, $context); fpassthru($fp); fclose($fp); ?>
在自己机器里面脚本如下:
<?php
var_dump($_COOKIE);
当运行脚本时候输出: