2012-08-12 176 views
2

我讓遠程服務器登錄system.For這個機器人,我編碼的東西,遠程登錄,捲曲

sample.php

<?php 
$EMAIL  = "***"; 
$PASSWORD = "***"; 
function cURL($url, $header=NULL, $cookie, $p=NULL) 
{ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, $header); 
    curl_setopt($ch, CURLOPT_NOBODY, $header); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    if ($p) { 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $p); 
    } 
    $result = curl_exec($ch); 
    if ($result) { 
     return $result; 
    } else { 
     return curl_error($ch); 
    } 
    curl_close($ch); 
} 
$a = cURL("http://forum.donanimhaber.com/login2.asp",true,null,"Login=$EMAIL&password=$PASSWORD"); 
preg_match('%Set-Cookie: ([^;]+);%',$a,$b); 
$c = cURL("http://forum.donanimhaber.com/login2.asp",true,$b[1],"Login=$EMAIL&password=$PASSWORD"); 
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d); 
for($i=0;$i<count($d[0]);$i++) 
    $cookie.=$d[1][$i].";"; 
echo cURL("forum.donanimhaber.com",null,$cookie,null); 
?> 

我使用此代碼www.myhost.com/ sample.php ...登錄成功。但我沒有重定向forum.donanimhaber.com ...在forum.donanimhaber.com,當我點擊任何鏈接時,我的瀏覽器重定向myhost.com/link.php並出現空白頁面正常要求爲forum.donanimhaber.com/link.php ...

回答

0

該代碼應生成頁面的確切HTML並輸出。該頁面中的所有鏈接都將是相對鏈接。像,<a href="/page.php>...</a>。所以當你點擊你實際上被重定向到mysite.com/page.php。因爲它可能是你的設置,你沒有找到404和空白頁面。

要克服這個問題,您應該更換所有鏈接以重定向到論壇。或者使用.htaccess toforce刪除您的主頁面以外的所有鏈接。

RewriteCond %{HTTP_HOST} ^website.com 
RewriteRule (.*) http://forum.xyz.com/$1 [R=301,L] 

# do not do any rewriting to this file 
RewriteRule index\.php$ - [L]