简体   繁体   English

使用cUrl登录我的网站

[英]Using cUrl to login my website

I am trying to login to my A site from my B site. 我试图从我的B网站登录到我的A网站。 So I simulate a login form using curl and I expect to redirect to my A site's main member page. 因此,我使用curl模拟了一个登录表单,并且希望重定向到我网站的主要成员页面。 But instead my B site url remain on my address bar and my browser shows my Site A login page. 但是,我的B网站网址仍然保留在我的地址栏中,浏览器显示了我的网站A登录页面。 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. 使用curl您的服务器向A发出请求并收到响应。 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. curl不会做这样的事情。 For example, use header('Location: http://a.com ') to redirect the client in step 4. 例如,在第4步中使用header('Location: http://a.com ')重定向客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM