ZachMEdwards Posted May 28, 2010 Share Posted May 28, 2010 function headers($method, $file, $host, $referer = "", $data = "") { $isPost = @stripos($method, "POST") !== FALSE; $headers = ($isPost ? "POST " : "GET ").$file." HTTP/1.1\r\n"; $headers .= "Host: ".$host."\r\n"; $headers .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3\r\n"; $headers .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $headers .= "Accept-Language: en-us,en;q=0.5\r\n"; $headers .= "Accept-Encoding: gzip,deflate\r\n"; $headers .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"; $headers .= "Keep-Alive: 115\r\n"; $headers .= "Connection: Close\r\n"; if(!empty($referer)) { $headers .= $referer."\r\n"; } if($isPost) { $headers .= "Content-Type: application/x-www-form-urlencoded\r\n"; $headers .= "Content-Length: ".strlen($data)."\r\n"; } if(!empty($cookies)) { $headers .= $cookies."\r\n"; } if($isPost) { $headers .= "\r\n".$data."\r\n\r\n"; } else { $headers .= "\r\n"; } return $headers; } Here's the headers I get when I call: $head = headers("POST", "http://www.mysite.com/index.php?postdata=here&and=such&foo=bar")); die("\"$head\""); I'm doing this same thing with GET requests and those work fine. Here's where I send the headers: if(!$fp) { die("$errstr ($errno)<br />\n"); } else { $out = ""; fwrite($fp, $head); while(!feof($fp)) { $out .= fgets($fp, 128); } fclose($fp); echo $out; } Thanks in advance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.