欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP如何设置头信息

程序员文章站 2022-04-03 09:04:09
...
本篇文章主要介绍PHP如何设置头信息,感兴趣的朋友参考下,希望对大家有所帮助。

代码如下:

<?php
/**
Accept application/json
Accept-Encoding gzip, deflate
Accept-Language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Connection keep-alive
Cookie mzys_is_frist_access=1; mzys_c_uuid=guest_215cbc0979b5bd2; mzys_access20130610=1; mzys_qz_uuid=d6d4640f93cb7a4; CNZZDATA30040410=cnzz_eid%3D1008690174-1370849811-http%253A%252F%252Fm.120ask.com%26ntime%3D1370855345%26cnzz_a%3D43%26retime%3D1370855484258%26sin%3D%26ltime%3D1370855484258%26rtime%3D0; PHPSESSID=4kacoqfe4ae33km3h0l2imjfd6
Host m.120ask.com
Referer http://m.120ask.com/health/show?page=2&id=84882&type=17
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0
X-Requested-With XMLHttpRequest
 */
$hdrs = array(
  'http' =>array('header' => 
   "Accept: application/json\r\n" .
   "Accept-Encoding: gzip, deflate\r\n" .
   "Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n" .
   "Accept-Encoding: gzip, deflate\r\n" .
   "Connection: keep-alive\r\n" .
   "Cookie: mzys_is_frist_access=1; mzys_c_uuid=guest_215cbc0979b5bd2; mzys_access20130610=1; mzys_qz_uuid=d6d4640f93cb7a4; CNZZDATA30040410=cnzz_eid%3D1008690174-1370849811-http%253A%252F%252Fm.120ask.com%26ntime%3D1370855345%26cnzz_a%3D43%26retime%3D1370855484258%26sin%3D%26ltime%3D1370855484258%26rtime%3D0; PHPSESSID=4kacoqfe4ae33km3h0l2imjfd6\r\n" .
   "Host: m.120ask.com\r\n" .
   "Referer: http://m.120ask.com/health/show?page=2&id=84882&type=17\r\n" .
   "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n" .
   "X-Requested-With: XMLHttpRequest",
   'timeout'=>2
  ),
);
$context = stream_context_create($hdrs);
//方式1
// $fp = fopen("http://m.120ask.com/health/show?page=2&id=84882&type=17", 'r', false, $context);
// fpassthru($fp);
// fclose($fp);
//方式2
//echo file_get_contents('http://m.120ask.com/health/show?page=2&id=84882&type=17', 0, $context);

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

关于PHP给文字内容中的关键字进行套红处理的方法

PHP中Restful api 实现错误提示返回值的方法

基于PHP绘制网站登录首页图片验证码的方法

以上就是PHP如何设置头信息的详细内容,更多请关注其它相关文章!

相关标签: php 信息 设置