I'm working on a piece of code the is run on a server and can be called as an XML feed for domains that are licensed to use it. So basically, lets say I'm on mydomain.com and want to use the feed. Using curl, I would do something like this:
$url = "http://www.myhostingdomain.com/surgeproto/feeds/xml/feed.xml";
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
echo $content;
The feed.xml is actually a PHP file that I'm simply mod rewriting so I can use the XML extension. Inside the feed.php file, I'm using $_SERVER['HTTP_REFERER']; to grab the calling domain, in this case "mydomain.com" which isn't working. I'm guessing this is because it's not a referer, but I wasn't sure which alternative to use.
Also, since I'm using mod_rewrite, I'm wondering if the rewrite rule, defined below, could be causing me to lose the referer somehow:
RewriteRule ^([0-9a-zA-Z_-]+)/feeds/xml/feed.xml$ /feeds/xml/feed\.php?username=$1 [NC]
I'd also like to make sure there's no way for curl or any other tool to "fake" the calling URL. Any help on this would be greatly appreciated!