Folks,
How and in what format are form variables passed to a remote server?
I'm trying to duplicate in php some html code that automatically submits a form to login to a site, and I think I'm having trouble creating the proper http headers.
Here's the html code:
<html>
<body onload="document.koc.submit();">
<form action="http://www.kingsofchaos.com/login.php" method="post" name=koc>
<input type="hidden" name="usrname" value="me">
<input type="hidden" name="uemail" value="email@email.com">
<input type="hidden" name="peeword" value="funkynumber">
</form>
</body>
</html>
And here is the PHP code I've written to send the data:
<?php
$koc_host = "www.kingsofchaos.com";
$koc_path = "/login.php";
$koc_fp = fsockopen($koc_host,80,$errno,$errstr,30);
$request = "SUBMIT $koc_path HTTP/1.1\r\n";
$request .= "Host: $koc_host\r\n";
$request .= "usrname:me\r\n";
$request .= "uemail:email@email.com\r\n";
$request .= "peeword:funkynumber\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($koc_fp, $request);
// print everything received from the server
while (!feof($koc_fp)) {
echo fgets($koc_fp);
}
fclose($koc_fp);
?>
From the server, I'm receiving this text:
HTTP/1.1 200 OK
Date: Tue, 25 Oct 2005 02:10:36 GMT
Server: Apache/1.3.33 (Unix) (Gentoo/Linux)
Set-Cookie: country=US; expires=Wed, 22-Feb-2006 02:10:36 GMT; path=/; domain=.kingsofchaos.com
Set-Cookie: koc_session=0c5d01c3a78c7c09de7ad2aed1e0f937; path=/; domain=.kingsofchaos.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
255f
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
The page loads with an error--apparently because the login information isn't recognized.
I'm assuming that the problem lies in my formatting of the form variables.
Alternatively, could it be that I should be using POST instead of SUBMIT?
$request = "POST $koc_path HTTP/1.1\r\n";
The server response is:
HTTP/1.1 302 Found
Date: Tue, 25 Oct 2005 02:15:27 GMT
Server: Apache/1.3.33 (Unix) (Gentoo/Linux)
Set-Cookie: country=US; expires=Wed, 22-Feb-2006 02:15:28 GMT; path=/; domain=.kingsofchaos.com
Set-Cookie: koc_session=c29d72694f9d9832b7da7f9628f6bab0; path=/; domain=.kingsofchaos.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: login.php
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
If I understand the 302 code, it indicates a temporary redirect and the new URL should be in the Location: field--but this points to login.php, which I thought we had just processed... Do I need to refresh to login.php, only this time with the cookie included? (by the way, how do I send a cookie as part of the headers?)
Thanx tons for any insight.
Curtis