简体   繁体   English

要登录站点,并在登录后重定向到php curl中的页面

[英]To login a site and after login redirect to a page in php curl

To login to the site I have used this. 要登录到该站点,我已经使用过此功能。 But after successfully login that how can i redirect to a page as i want in the website. 但是成功登录后,我该如何重定向到我想要的网站页面。

For login by php curl i used this. 通过php curl登录,我使用了这个。

 $loginUrl = 'https://secure.propertyshark.com/mason/Accounts/logon.html';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $loginUrl);
    curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "email=myemail@hotmail.com&password=mypassword");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
$cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    $answer = curl_exec($ch);
    if (curl_error($ch)) {
        echo curl_error($ch);
    }
    curl_setopt( $ch, 'http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens-NY-11422/');
    echo $answer;

But i am not sure it is working or not, So i want how can i confirm about login and redirect to "' http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens-NY-11422/ " page. 但是我不确定它是否正常工作,因此我想如何确认登录并重定向到“' http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens -NY-11422 / “页面。

Now i am using this, but not working. 现在,我正在使用此功能,但无法正常工作。

<?php
$loginUrl = 'https://secure.propertyshark.com/mason/Accounts/logon.html';
$ch1 = curl_init();
$cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
curl_setopt($ch1, CURLOPT_URL, $loginUrl);
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch1, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, "email=myemail@hotmail.com&password=password");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_COOKIESESSION, true);


$next_page = 'http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens-NY-11422/';
$ch2 = curl_init();
$cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
curl_setopt($ch2, CURLOPT_URL, $next_page);
curl_setopt($ch2, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);

$answer = curl_exec($ch2);
if (curl_error($ch2)) {
    echo curl_error($ch2);
}

echo $answer;
$cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);

you need to add cookie file opt and after login make another curl request to next page 您需要添加cookie文件opt,并在登录后向下一页提出另一个curl请求

LATER EDIT: 之后编辑:

        $loginUrl = 'https://secure.propertyshark.com/mason/Accounts/logon.html';
        $ch1 = curl_init();
        $cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
        curl_setopt($ch1, CURLOPT_URL, $loginUrl);
        curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie);
        curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie);
        curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, TRUE);

        ............


        $next_page = 'http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens-NY-11422/';
        $ch2 = curl_init();
        $cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt';
        curl_setopt($ch2, CURLOPT_URL, $next_page);
        curl_setopt($ch2, CURLOPT_COOKIEJAR, $cookie);
        curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);
        ............

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

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