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

PHP使用file_get_content设置头信息的方法

程序员文章站 2024-04-01 17:54:52
本文实例讲述了php使用file_get_content设置头信息的方法。分享给大家供大家参考,具体如下: 直接上代码:

本文实例讲述了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);

更多关于php相关内容感兴趣的读者可查看本站专题:《php基本语法入门教程》、《php错误与异常处理方法总结》及《php常用函数与技巧总结

希望本文所述对大家php程序设计有所帮助。