很多站长朋友们都不太清楚Headerphp获取,今天小编就来给大家整理Headerphp获取,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php中怎样得到客户端的http请求header所有信息 2、 PHP获取不到自定义Header参数 3、 PHP怎么获取表单提交的数据啊? 4、 PHP 用 curl 获取指定网址的 header 5、 php 如何获取 客户端http header php中怎样得到客户端的http请求header所有信息<?php
ob_end_flush();
print_r(apache_request_headers());
?>
PHP获取不到自定义Header参数项目开发中经常会用到通过Header来传递参数,有时可能会出现通过$_SERVER无法获取到Header中自定义的参数,可以尝试通过下面的方法来解决。
在Nginx的配置文件中(即:nginx.conf)添加下面的配置项,然后重启Nginx服务即可
underscores_in_headers on; # 该配置项默认值为off
PHP怎么获取表单提交的数据啊?一、用file_get_contents以get方式获取内容,需要输入内容为:
1、<?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?>
二、用file_get_contents函数,以post方式获取url,需要输入内容为
1、<?php
2、$url='';
3、$data=array('foo'=>'bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=>array(
7、 'method'=>'POST',
8、 'header'=>"Content-type:application/x-www-form-urlencoded\r\n".
9、 "Content-Length:".strlen($data)."\r\n",
10、 'content'=>$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?>
三、用fopen打开url,以get方式获取内容,需要输入内容为
1、<?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//获取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}<br>":
8、echo"urlbody:$result";
9、fclose($fp);
10、?>
四、用fopen打开url,以post方式获取内容,需要输入内容为
1、<?php
2、$data=array('foo2'=>'bar2','foo3'=>'bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=>array(
6、'method'=>'POST',
7、'header'=>"Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=>$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?>
五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie: $cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//获取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、 returnfalse;
35、}
36、?>
参考资料:
php-file_get_contents
PHP 用 curl 获取指定网址的 headercurl_setopt($curl, CURLOPT_NOBODY,1); //启用时将不对HTML中的BODY部分进行输出。
php 如何获取 客户端http header<?php
$dir=$HTTP_GET_VARS["dir"]; //.......取得上个页面传递来的路径
$file=$HTTP_GET_VARS["file"]; //.......取得传递来的文件名
$url=parse_url($HTTP_REFERER); /*......取得前一页面的URL地址,并将其放入一个数组中*/
if($url[host]!=$HTTP_HOST){echo "要下载本软件请到<a href=;东方小屋</a>";exit;} /*检查来源网站是不是自己的网站,如果不是,返回“要下载本……”*/
if(empty($dir))$dir="/"; //......如果路径名为空,则为指定根目录
if(empty($file)){echo "未指定要下载的文件!";exit;} /*如果文件名为空,返回“未指定……”*/
$rootdir="文件存放的根目录";//......你的下载路径根目录
$realurl=$rootdir.$dir; //.......取得你的下载目录
chdir($realurl); //......将当前目录转到下载目录中
if(!file_exists($file)){echo "对不起,此链接已经失效,请在下载页面上向我们报告,谢谢!";exit;} //......测试文件是否存在
$filename=$file;
//发送文件头信息
header("Cache-control: private"); // fix for IE
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($filename));
header("Content-Disposition: attachment; filename=$filename");
$fp = fopen($filename, 'r'); //以读取方式打开指定文件
fpassthru($fp); // ** CORRECT ** 以二进制方式读取文件
fclose($fp); // 关闭文件
?>
关于Headerphp获取的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于Headerphp获取 php curl获取header的详细内容...