hi,
I am trying to send a set of headers off to a given page, read the response and then send that has header for the current page. I think I have relatively workable code:
PHP:-----------------------------------------
//build the request
$request=var1=val1&var2=val2
// Build the header
$header = "POST <a href="http://www.site.com/page.asp" target="blank">http://www.site.com/page.asp</a> HTTP/1.0\r\n";
$header.="Accept: /\r\n";
$header.="Accept-Language: en-gb\r\n";
$header.="Content-Type: application/x-www-form-urlencoded\r\n";
$header.="User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\r\n";
$header.="Host: <a href="http://www.site.com\r\n" target="blank">http://www.site.com\r\n</a>";
$header .= "Content-length: " . strlen($request) . "\r\n";
$header.="Connection: Keep-Alive\r\n\r\n";
// Open the connection
$fp = fsockopen("http://www.site.com", 80, &$err_num, &$err_msg, 30);
if ($fp)
{
// Send everything
fputs($fp, $header.$request);
// Get the response
while (!feof($fp))
$response .= fgets($fp, 128);
}
fclose ($fp);
//parse header
$headers = substr($response, 0, strpos($response, "\r\n\r\n"));
$list = explode("\r\n", $headers);
for($i = 0, $count = sizeof($list); $i < $count; ++$i)
{
header($list[$i]);
}
/PHP---------------------------------
I have no problem in sending the headers or retrieving them, but most of the headers I receive and set do not seem to have an effect - for instance, session cookies are ignored etc... (even if making sure the "domain" value of the cookie is set to the correct domain...)
The only workaround I have so far is by creating a self-submitting form to www.site.com/page.asp w/ hidden values, but that's not very satisfactory from a security point of view - are there any better ways of doing this?
thanks,
Elie