我正在尝试使用我的远程登录到一个网站。用户需要在我的网站上输入他们的用户名和密码,如果他们在我的网站上注册,他们的登录凭据将被发送到另一个网站,并且将检索一个页面。
我坚持将用户的数据发送到原始网站。原始网站的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 :(得分:0)
这是不安全的,但这是一种方法
<?php
if (isset($_POST['username']))
{
file_get_contents("http://otherwebsite/page.php?login=".$_POST['username']."&password=".$_POST['password'])
}
?>