如何使用 fsockopen 从 cookie.txt 发送 cookie 和 http 请求?

How to send cookie alongside http request from cookie.txt using fsockopen?

我正在搜索如何在不等待响应完成的情况下使用 curl(发送 http 请求),因为我只想触发许多操作而不期望结果。经过一段时间的搜索,我找到了解决方案 Here,但我遇到了问题。
问题是我不知道如何传递我保存在 .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 当我搜索时,我发现了 2 种格式的 cookie
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

2。 Cookie默认格式(参考:Here

csrf_cookie_name=cac551cc13952929efd2507797fff687; ci_session=umt92quvucfu333p1co19b83i3jaglm9;

我尝试使用此行代码发送 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: csrf_cookie_name=cac551cc13952929efd2507797fff687; ci_session=umt92quvucfu333p1co19b83i3jaglm9;";