Hello,
I don't know if the following is possible or not. But if I don't ask, I won't know.
There is an html form on a remote site with the fields: Username, password.
I can visit the website, and login successfully.
However, I'm wondering if it's possible to login without visiting the website.
In other words, can I create a similar form on a remote server, and do a remote POST?
I've tried the following code, but it doesn't log me in. It simply returns to the login form.
$formdata = array (
"user" => "myusername",
"password" => "mypassword"
);
foreach($formdata AS $key => $val) {
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen($host, 80, $errno, $errstr, $timeout = 30);
if(!$fp) {
echo "ERROR opening socket";
}
else {
fputs($fp, "POST $action HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
while(!feof($fp)){
$data .= @fgets($fp, 1024);
}
fclose($fp);