Using cUrl to login my website
I am trying to login to my A site from my B site. So I simulate a login form using curl and I expect to redirect to my A site's main member page. But instead my B site url remain on my address bar and my browser shows my Si开发者_开发技巧te A login page. I am new to curl. Thank you for reading.
$cc = curl_init($url);
curl_setopt($cc, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($cc, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($cc, CURLOPT_HEADER, true);
curl_setopt($cc, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cc, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cc, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cc, CURLOPT_POST, true);
curl_setopt($cc, CURLOPT_POSTFIELDS, $postString);
return curl_exec($cc);
curl_close($cc);
//echo $result;
//exit;
Using curl
your server makes a request to A and receives a response. It has nothing to do with the client.
1) request 2) request (curl)
---> --->
Client (browser) Server B Server A
<--- <---
4) response 3) response
If you want to tell the client something or redirect him, you have to do so in your response to the client. curl
won't do anything like this. For example, use header('Location: http://a.com')
to redirect the client in step 4.
精彩评论