2014-02-05 84 views
0

我一直在圍繞這個網站尋找解決我的問題,一些答案看起來接近,但沒有那麼多,找到解決我的問題 我有PHP捲曲登錄到特定的網站,並重定向到一定聯繫,而登錄。簡單的捲曲重定向

***First to log:*** 

$ ch = curl_init();

 curl_setopt($ch, CURLOPT_URL, 'https >somesite'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); 
    curl_setopt($ch, CURLOPT_COOKIESESSION, 1); 
    curl_setopt($ch, CURLOPT_USERAGENT, $uagent); 
    curl_setopt($ch, CURLOPT_REFERER, 'some other site'); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 220); 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).DS.'cookies.txt'); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).DS.'cookies.txt'); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,'userid='.$log.'&password='.$pass.); 
    $content = curl_exec($ch) 

***then run this to get away from page with ads *** 

    $info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    $fnd='ads'; ***// check to see if has ads*** 
    $pos=strpos($info, $fnd); 
    if ($pos!==false) 
     { 

$url1 = "https - link to redirect while logged id"; // ***I have this link for sure*** 
$ch1 = curl_init(); 
curl_setopt ($ch1, CURLOPT_URL, $url1); 
curl_setopt ($ch1, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt ($ch1, CURLOPT_USERAGENT, $uagent); 
curl_setopt($ch1, CURLOPT_HEADER, 1); 
curl_setopt ($ch1, CURLOPT_COOKIESESSION, 0); 
curl_setopt ($ch1, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch1, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT ,100); 
curl_setopt ($ch1, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch1, CURLOPT_COOKIEJAR, dirname(__FILE__).DS.'cookies.txt'); 
curl_setopt ($ch1, CURLOPT_COOKIEFILE, dirname(__FILE__).DS.'cookies.txt'); 
curl_setopt ($ch1, CURLOPT_POST, 0); 

$content = curl_exec ($ch1); 

但這是行不通的。

誰會可否回答我?

謝謝。

+0

你能更多地討論「不靈」了一下?例如,你有錯誤嗎? – Martijn

回答

0

我聽到一個恐怖電影中的對話框(不知道雖然)很長時間回來「Easy Pizzy,這意味着瘋狂」。你的問題的解決方案是容易的,但直到你知道它:-)

閉上你的捲髮,以確保它保存的cookies到文件中。否則,它總是空的,因此不打算第二個電話。

// use it before second curl call 
curl_close($ch); 

事實上,在需求完成後關閉curl實例總是一個好習慣!

+0

謝謝哈桑。 – user3275542