最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php stream_context_create函数
时间:2010-12-10 编辑:简简单单 来源:一聚教程网
函数原型:resource stream_context_create ([ array $options [, array $params ]] )
看个实例
//定义options数组
$opts=array
(
'http'=>array
(
'method'=>"get",
'header'=>"accept-language: enrn"."cookie: foo=barrn"
)
);
//创建数据流上下文
$context=stream_context_create($opts);
/*向指定地址发送http请求
请求中包含附加的头部信息*/
$fp=fopen('http://www.111com.net','r',false,$context);
//输出文件指针处的所有数据
fpassthru($fp);
//关闭文件
fclose($fp);
/*
该代码的输出结果为:即请求的cookie值
array
(
[foo] => bar
)
*/
实例二
$default_opts=array
(
'http'=>array
(
'method'=>"get",
'header'=>"accept-language: enrn"."cookie: foo=bar",
'proxy'=>"tcp://10.54.1.39:8000"
)
);
$alternate_opts=array
(
'http'=>array
(
'method'=>"post",
'header'=>"content-type: application/x-www-form-urlencodedrn"."content-length: " . strlen("baz=bomb"),
'content'=>"baz=bomb"
)
);
$default=stream_context_get_default($default_opts);
$alternate=stream_context_create($alternate_opts);
/* sends a regular get request to proxy server at 10.54.1.39
* for www.example.com using context options specified in $default_opts
*/
readfile('http://www.example.com');
/* sends a post request directly to www.example.com
* using context options specified in $alternate_opts
*/
readfile('http://www.example.com', false, $alternate);
-
上一个: php中打开目录并输出目录文件实现代码
-
下一个: php中目录操作函数(删除,创建,判断)
相关文章
- php中bind_param()函数用法分析 08-03
- PHP函数rtrim()使用中的怪异现象分析 05-01
- php 基础函数 03-27
- php 常用的系统函数 03-17
- 给大家分享几个常用的PHP函数 01-19
- PHP162个常用函数总结 12-28