2016-03-19 54 views
0

我使用此代碼/腳本:PHP /捲曲 - 重定向,並保持在該功能是

<?php 

//Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777 
function login($url,$data){ 
    $fp = fopen("cookie.txt", "w"); 
    fclose($fp); 
    $login = curl_init(); 
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt"); 
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt"); 
    curl_setopt($login, CURLOPT_TIMEOUT, 40000); 
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($login, CURLOPT_URL, $url); 
    curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); 
    curl_setopt($login, CURLOPT_POST, TRUE); 
    curl_setopt($login, CURLOPT_POSTFIELDS, $data); 
    ob_start(); 
    return curl_exec ($login); 
    ob_end_clean(); 
    curl_close ($login); 
    unset($login);  
}     

function grab_page($site){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 40); 
    curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:")); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 
    curl_setopt($ch, CURLOPT_URL, $site); 
    ob_start(); 
    return curl_exec ($ch); 
    ob_end_clean(); 
    curl_close ($ch); 
} 

function post_data($site,$data,$data){ 
    $datapost = curl_init(); 
     $headers = array("Expect:"); 
    curl_setopt($datapost, CURLOPT_URL, $site); 
     curl_setopt($datapost, CURLOPT_TIMEOUT, 40000); 
     curl_setopt($datapost, CURLOPT_HEADER, FALSE); 
     curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($datapost, CURLOPT_POST, TRUE); 
    curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); 
     curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt"); 
    ob_start(); 
    return curl_exec ($datapost); 
    ob_end_clean(); 
    curl_close ($datapost); 
    unset($datapost); 

} 

?> 

這個腳本在我的另一個網站,並自動完成某些功能上的VPS運行。我想在執行該功能後重定向他留在我的vps上的原始網站。

例如:我的代碼/腳本像google.com/page1一樣工作,自動執行功能到page4,當我使用重定向時,他再次啓動google.com/page1,我想在剩餘page4時重定向。

是posibile原始網站有自動刷新或什麼?

對不起,英語不好。

+0

你總是喊? –

+0

什麼?我不明白你說什麼?請問例如 – Smon

回答

0

您可以使用curl_getinfo()。

http://php.net/manual/en/function.curl-getinfo.php

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 

例:

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 40); 
    curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:")); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 
    curl_setopt($ch, CURLOPT_URL, $site); 
    ob_start(); 
    curl_exec ($ch); 
$last_redirected_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    ob_end_clean(); 
    curl_close ($ch); 

echo $last_redirected_url; 
+0

? echo curl_getinfo($ ch,http://google.com);只是這個?我不需要別的東西? – Smon

+0

我添加了示例 –

+0

感謝腳本,但即時通訊新手在PHP捲曲..我知道如何使用,如果我有完整的例證..請?我的意思是我需要在這個腳本中添加我的網站?或者我需要替換的地方? – Smon