久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

file_get_contents 接收 cookie

file_get_contents receive cookies(file_get_contents 接收 cookie)
本文介紹了file_get_contents 接收 cookie的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在執行 file_get_contents 請求時,是否可以接收遠程服務器設置的 cookie?

Is it possible to receive the cookies set by the remote server when doing a file_get_contents request?

我需要 php 來執行 http 請求,存儲 cookie,然后使用存儲的 cookie 發出第二個 http 請求.

I need php to do a http request, store the cookies, and then make a second http request using the stored cookies.

推薦答案

你應該使用 cURL 為此,cURL 實現了一個叫做 cookie jar 的特性,它允許將 cookie 保存在一個文件中,并在后續請求中重用它們.

you should use cURL for that purpose, cURL implement a feature called the cookie jar which permit to save cookies in a file and reuse them for subsequent request(s).

這里有一個快速的代碼片段如何做:

Here come a quick code snipet how to do it:

/* STEP 1. let’s create a cookie file */
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
/* STEP 2. visit the homepage to set the cookie properly */
$ch = curl_init ("http://somedomain.com/");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

/* STEP 3. visit cookiepage.php */
$ch = curl_init ("http://somedomain.com/cookiepage.php");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

注意:必須注意,您應該安裝 pecl 擴展(或在 PHP 中編譯),否則您將無法訪問 cURL API.

note: has to be noted you should have the pecl extension (or compiled in PHP) installed or you won't have access to the cURL API.

這篇關于file_get_contents 接收 cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 成人精品国产一区二区4080 | 久久国产欧美日韩精品 | 一区二区三区电影在线观看 | 亚洲精品欧美一区二区三区 | 一级大黄| 一级片免费视频 | 国产一区二区免费电影 | 欧美国产一区二区 | 美女在线视频一区二区三区 | 精品二区 | 国产精品永久免费观看 | 午夜不卡一区二区 | 一级毛片在线播放 | av在线播放网站 | 在线观看成人 | 亚洲精品久久久一区二区三区 | 久久久久国产精品午夜一区 | 91成人小视频 | 久久中文视频 | 国产高清在线精品 | 久久久久国色av免费观看性色 | 精品视频999| 国产精品1区 | 小h片免费观看久久久久 | 欧一区| 国产欧美日韩精品一区 | 福利在线观看 | 日韩在线免费观看视频 | 精品欧美一区二区三区久久久小说 | 欧美日韩一二三区 | 在线高清免费观看视频 | 日韩免费在线 | 黄色国产视频 | 超碰在线国产 | 成人一区二 | 国产精品波多野结衣 | 国产精品美女久久久久久免费 | 91偷拍精品一区二区三区 | 久久久久91 | 亚洲网站在线观看 | 亚洲国产成人精品女人久久久 |