doudoulb1234
2016-09-22 05:58
浏览 70
已采纳

登录站点并在登录后重定向到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.

 $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.

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;
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douyan2470 2016-09-22 06:03
    最佳回答
    $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

    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);
            ............
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题