Alter HTTP_REFERER and/or User Agent
Posted: Thu Aug 30, 2007 2:07 pm
feyd | Please use
Thank you in advance for your assistance in bringing me over "from the dark side" 
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
I am a **long-time** CF guy who has been forced to do some quickie stuff in PHP. Unfortunately, I don't know jack about PHP, beyond the basics. I have a very simple script that I've written (see below) that performs an http get request on the provided URL, and then spits out the resulting page. I am wondering if there is an easy way to enhance it by allowing for the alteration of the 'referrer' and/or the 'user agent' that is sent with the request?Code: Select all
<?php
function fetchURL( $url ) {
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0)
$port = 80;
$path = $url_parsed["path"];
if ($url_parsed["query"] != "")
$path .= "?".$url_parsed["query"];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$body = false;
while (!feof($fp)) {
$s = fgets($fp, 1024);
if ( $body )
$in .= $s;
if ( $s == "\r\n" )
$body = true;
}
fclose($fp);
return $in;
}
function isValidURL($url) {
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
if (isset($_GET['lnk']) && isValidURL($_GET['lnk'])) {
echo fetchURL($_GET['lnk']);
} else {
echo "An invalid URL was provided.";
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]