Send a POST and receive cookies in PHP
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百科
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
精彩评论