2016-03-19 18 views
0

nerede kalır: başka bir web sitesine ve bazı işlevler otomatik komple benim VPS çalıştırmakPHP/cURL - yönlendir ve fonksiyon bu kodu/komut dosyasını kullanmak

<?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); 

} 

?> 

Bu senaryoyu. Vps'imde kaldığı orijinal web sitesini yeniden yönlendirmek için işlevi yerine getirmesini istiyorum.

örnek: kodum/google.com/page1 gibi işlevlerim otomatik olarak sayfa4 işlevini çalıştırır ve yönlendirmeyi kullandığımda tekrar google.com/page1 adresine başlar ve yönlendirdiğimde sayfa4'ü kalmasını istiyorum.

Orijinal web sitesinin otomatik yenileme veya bir şey var mı?

Kötü ingilizce için özür dilerim.

+0

hep bağırmak mı? –

+0

ne? ne dediğini anlayamıyorum – Smon

cevap

0

curl_getinfo() öğesini kullanabilirsiniz.

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

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 

ÖRNEK:

$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

örnek lütfen? echo curl_getinfo ($ ch, http://google.com); sadece bu? başka bir şeye ihtiyacım yok mu? – Smon

+0

Örnek için –

+0

ekledim ama betik için teşekkürler ama php curl'de yeni kullanıcı var .. Eğer tam kapsamlı olursam nasıl kullanacağımı biliyorum .. lütfen? Web sitemi bu yazıya eklemem gereken yere mi ihtiyacım var? veya değiştirmem gereken yere mi? – Smon

İlgili konular