2013-02-13 58 views
0

我在正規網站上的登錄表單。如果用戶使用此表單登錄我的網站,他們應該同時登錄論壇。怎麼做 ?有些人說使用SSI.php,但這個文件給了我另一種形式來向SMF進行身份驗證。如何登錄到SMF論壇從另一種形式不使用SMF登錄表單

+0

通過再現從其他論壇的代碼完全相同的POST請求? – ZarkDev 2013-02-13 12:36:13

+0

是的。我爲這篇文章準備了數據。只有3個參數。 – 2013-02-13 12:40:43

回答

0

好了,所以如果你想只執行相同的POST請求的登錄表單也但從另一個PHP代碼,這個功能可能會感興趣:


大部分代碼是從http://www.jonasjohn.de/snippets/php/post-request.htm

function post_request($url, $data, $referer='') { 

    // Convert the data array into URL Parameters like a=b&foo=bar etc. 
    $data = http_build_query($data); 

    // parse the given URL 
    $url = parse_url($url); 

    if ($url['scheme'] != 'http') { 
     die('Error: Only HTTP request are supported !'); 
    } 

    // extract host and path: 
    $host = $url['host']; 
    $path = $url['path']; 

    // open a socket connection on port 80 - timeout: 30 sec 
    $fp = fsockopen($host, 80, $errno, $errstr, 30); 

    if ($fp){ 

     // send the request headers: 
     fputs($fp, "POST $path HTTP/1.1\r\n"); 
     fputs($fp, "Host: $host\r\n"); 

     if ($referer != '') 
      fputs($fp, "Referer: $referer\r\n"); 

     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
     fputs($fp, "Content-length: ". strlen($data) ."\r\n"); 
     fputs($fp, "Connection: close\r\n\r\n"); 
     fputs($fp, $data); 

     $result = ''; 
     while(!feof($fp)) { 
      // receive the results of the request 
      $result .= fgets($fp, 128); 
     } 
    } 
    else { 
     return array(
      'status' => 'err', 
      'error' => "$errstr ($errno)" 
     ); 
    } 

    // close the socket connection: 
    fclose($fp); 

    // split the result header from the content 
    $result = explode("\r\n\r\n", $result, 2); 

    $header = isset($result[0]) ? $result[0] : ''; 
    $content = isset($result[1]) ? $result[1] : ''; 

    // return as structured array: 
    return array(
     'status' => 'ok', 
     'header' => $header, 
     'content' => $content 
    ); 
} 

的數據參數是一個數組如下面

$post_data = array(
     'login' => 'yourLogin', 
     'pass' => 'yourPass', 
     ... 
); 

,然後只需調用帶有URL的方法(原始形式的行動?):

$result = post_request('http://www.smf-forum1.com/login.php', $post_data); 

希望這是你所期望的,如果沒有,我沒有理解這個問題:/

+0

感謝您的回覆。你明白我的理解。我試過這段代碼,但它給了我一個錯誤。錯誤:連接被拒絕(111)。我不知道這是關於smf的錯誤...我正在研究,但也許你有任何建議。 – 2013-02-13 15:53:24

+0

抱歉遲到回覆。我從不嘗試這樣的事情,所以不知道這是什麼錯誤。但我認爲錯誤可能是拒絕您的請求的服務器配置。對不起,但我真的不能幫助更多:無論如何感謝s – ZarkDev 2013-02-18 07:26:14

+0

。我用iframe解決了我的問題:) – 2013-02-18 12:10:09

0

你可以使用CURL Php來實現這一點。

下面是一個例子

$username="username"; 
$password="password"; 
$url="http://www.simplemachines.org/"; 
$cookie="cookie.txt"; 

$postdata = "user=".$username."&passwrd=".$password."&cookielength=-1"; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result; 
curl_close($ch); 
+0

你能解釋一下嗎?我試過這個代碼。但沒有發生。沒有任何錯誤或什麼。 – 2013-02-14 07:29:09