开发者

Send a POST and receive cookies in PHP

I have a website that needs to send a POST to a website, than read the cookies returned (in an HTTP way - aka Set-Cookie: ...)

I tried this code:

<?php
$ch = curl_init('http://www.site.co.il/login.php?do=login');
 curl_setopt ($ch, CURLOPT_POST, 1);
 curl_setopt ($ch, CURLOPT_POSTFIELDS, "datadata");
 $a = curl_exec($ch);
 curl_close($ch);

but it only loads the website in the browser (without me even writing print($a) !!!) - although it DOES show me 'connect successfully' - but ofcorse doesn't set the cookie.开发者_Python百科

I basically want to make a proxy-like application, where the cookies received from site.co.il would be stored on the clients machine, but each time it connects to my site, it will grab the cookies and do a POST to site.co.il with them.

Any example of grabbing the Set-Cookie: header from the returned HTTP will be appreciated.

Thank you !


try with CURLOPT_HEADER set to true and trim out BODY content

<?php
    $ch = curl_init('http://www.site.co.il/login.php?do=login');
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "datadata");
    curl_setopt ($ch, CURLOPT_HEADER, TRUE); 
    curl_setopt ($ch, CURLOPT_NOBODY, TRUE);
    $a = curl_exec($ch);
    curl_close($ch);
?>


Mihai is right. Here's some code that does it: http://us.php.net/manual/en/function.curl-exec.php#92580

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜