PHP cURL 登录不起作用


PHP cURL login doesn't work

我正在尝试使用我的网站创建对一个网站的远程登录。用户需要在我的网站上输入他们的用户名和密码,如果他们注册到我的网站,他们的登录凭据将被发送到另一个网站,并将检索一个页面。

我无法将用户的数据发送到原始站点。原始站点的视图源是这个..

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

任何帮助将不胜感激,提前感谢。

这是不安全的,但这是一种方法

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