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);
            ............
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失