2016-09-22 185 views
0

要登錄該站點,我已經使用過了。但成功登錄後,我怎麼能重定向到一個頁面,因爲我想在網站上。要登錄網站並登錄後重定向到php curl的頁面

對於通過php捲曲登錄我用這個。

$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 protected]&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; 

,但我不知道它是否工作,所以我想我怎麼能確認有關登錄和重定向到「」 http://www.propertyshark.com/mason/Property/619443/133-32-244-St-Queens-NY-11422/」頁面。

現在我正在使用這個,但不工作。

<?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 protected]&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
$cookie = getcwd().DIRECTORY_SEPARATOR.'cookie.txt'; 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 

你需要添加cookie文件opt和登錄之後再拍捲曲的請求下頁

以後編輯:

 $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); 
     ............ 
+0

我應該添加此的腳本和創建的cookie .txt文件? – Ranjit

+0

添加到腳本中,不需要緩存cookies.txt ...自動創建 – CatalinB

+0

如何重定向頁面?我認爲,這需要花費太多時間還是不行?我已經用腳本添加了這個問題。請檢查 – Ranjit