2014-12-04 54 views
-2

我想創建一個遠程登錄到一個網站使用我的。用戶需要在我的網站上輸入他們的用戶名和密碼,如果他們已經註冊到我的網站,他們的登錄憑證將被髮送到另一個網站,並將檢索一個頁面。PHP cURL登錄不起作用

我被困在將用戶數據發送到原始網站。原網站的viewsource是這樣的..

<form method=post> 
<input type="hidden" name="action" value="logon"> 
<table border=0> 
<tr> 
<td>Username:</td> 
<td><input name="username" type="text" size=30></td> 
</tr> 
<tr> 
<td>Password:</td> 
<td><input name="password" type="password" size=30></td> 
</tr> 
<td></td> 
<td align="left"><input type=submit value="Sign In"></td> 
</tr> 
<tr> 
<td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <a href="?action=newuser"><font size=-1 color="#0000EE">Sign UP Now !</font></a></td> 
</tr> 
</table> 

這是位於http://www.example.com/index.php

我曾嘗試這個代碼,但沒有作品。這是我從另一個問題回答過的人那裏得到的。

<?php 
$username="username"; 
$password="password"; 
$url="http://www.example.com/index.php"; 

$postdata = "username=".$username."&password=".$password; 

$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, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
header('Location: track.html'); 
//echo $result; 
curl_close($ch); 
?> 

任何幫助將不勝感激,提前致謝。

+0

你的URL不起作用 – 2014-12-04 09:26:01

+0

哪裏是你的代碼的其餘部分? – 2014-12-04 09:26:26

+0

我在代碼中看不到cURL,只有HTML – Justinas 2014-12-04 09:27:03

回答

0

這是不安全的,但它是一個辦法做到這一點

<?php 
if (isset($_POST['username'])) 
{ 
    file_get_contents("http://otherwebsite/page.php?login=".$_POST['username']."&password=".$_POST['password']) 
} 
?> 
+0

我在哪裏粘貼這個?抱歉,剛接觸php。 – brvnbld 2014-12-04 09:30:56

+0

在URL中傳遞用戶名和密碼,這是不安全的.. :) – 2014-12-04 09:34:04

+0

@AlExMeRcER在代碼的頂部。 – blue112 2014-12-04 09:42:13