PHP使用file_get_content设置头信息的方法
发布:smiling 来源: PHP粉丝网 添加日期:2021-07-09 17:26:33 浏览: 评论:0
这篇文章主要介绍了PHP使用file_get_content设置头信息的方法,结合实例形式对比分析了PHP使用fopen及file_get_contents设置及获取头信息的相关技巧,需要的朋友可以参考下。
本文实例讲述了PHP使用file_get_content设置头信息的方法,分享给大家供大家参考,具体如下:
直接上代码:
- <?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);
Tags: file_get_content
相关文章
- ·解决php中file_get_contents 读取大文件返回false问题(2013-12-08)
- ·解决file_get_contents遇到中文文件名无法打开问题(2013-12-08)
- ·php file_get_contents()读取采集远程文件内容(2014-03-24)
- ·PHP fopen()和 file_get_contents()应用与差异介绍(2020-10-29)
- ·php 使用file_get_contents读取大文件的方法(2021-04-26)
- ·PHP使用fopen与file_get_contents读取文件实例分享(2021-07-13)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)