Php 如何使用fsockopen从cookie.txt发送cookie和http请求?
我正在搜索如何在不等待响应完成的情况下使用curl(发送http请求),因为我只想触发许多操作,而不希望得到结果。经过一段时间的搜索,我找到了一个解决方案,但我有一个问题。Php 如何使用fsockopen从cookie.txt发送cookie和http请求?,php,cookies,http-headers,fsockopen,Php,Cookies,Http Headers,Fsockopen,我正在搜索如何在不等待响应完成的情况下使用curl(发送http请求),因为我只想触发许多操作,而不希望得到结果。经过一段时间的搜索,我找到了一个解决方案,但我有一个问题。问题是我不知道如何传递保存在.txt中的cookie,我想使用此请求发送它 function curl_post_async($url, $params) { foreach ($params as $key => &$val) { if (is_array($val)) $val = i
问题是我不知道如何传递保存在.txt中的cookie,我想使用此请求发送它
function curl_post_async($url, $params)
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
如何使用上述代码从.txt文件发送cookie?经过研究,我解决了如何从cookies.txt发送cookie的问题
搜索时,我发现了两种格式的cookies
1.网景
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_.site.com TRUE / FALSE 1517538526 __cfduid dc0d1a86523f4fa68c7c9e19b084aa1651486002526
#HttpOnly_www.site.com FALSE / FALSE 1486006126 cisession a914d92115f6a6d73124ac5de4c49e070b872b98
二,。Cookie默认格式(参考:)
我试图用这行代码发送cookie格式1
$out.= "Cookie: ".file_get_contents(getcwd().$cookie); //where getcwd().$cookie is location of the cookie.txt with format no.1
我试过了,但失败了。但是,如果cookie.txt的cookie值是2号格式,我发送了该cookie,它成功发送并可以读取。
发送cookie的结论:
$out.= "Cookie: ".file_get_contents(getcwd().$cookie); //where getcwd().$cookie is location of the cookie.txt with format no.1
$out.= "Cookie: csrf_cookie_name=cac551cc13952929efd2507797fff687; ci_session=umt92quvucfu333p1co19b83i3jaglm9;";