php http request


php http request

$post_data = array(
        'url' => $all[2],
        'op' => 'sv',
        'sid' => 1
    );
// Send a request to example.com 
$result = post_request('http://www.yahoo.com', $post_data);
function PostRequest($url) { 
    $opts = array('http' =>
        array(
            'method'  => 'GET',
            'header'  => "Content-type: application/x-www-form-urlencoded'r'n"."Accept-language: en'r'n" .
              "Cookie: member_id=8593099'r'n" .
              "Cookie: pass_hash=fad917fe75e1059f85fc6d9bb6f7a19f'r'n".
              "Cookie: session_id=279fe56fd87e5371dc7e1c9f66c27522"
        )
    );
    $context  = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);
    return $result; 
}  

我能够发送请求,但是我的操作需要登录才能执行。即使我登录了,它也将我归类为未登录。

我使用localhost发送请求。是因为定义域不同吗?我已经为我的本地主机复制了登录cookie,但它仍然不起作用。什么好主意吗?我试图做的是用php发送http请求。我的请求已经发出,但是我的目的地无法检测到cookie,并且声称我没有登录。

我不太确定你想要完成什么,因为你发布的代码不是很清楚。post_request()不是一个本地的php函数,所以你必须给我们一个它的样本,以便我们能够进一步帮助你。

我还是建议你检查一下你是否把session_start();放在了你的php文件的最上面——它确保你能够访问session/cookie