PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The script on my site provides the image and everything works like a charm. But, I need to know how to reliably get the url of the page loading the image.
I tried
$HTTP_REFERER;
$HTTP_SERVER_VARS['HTTP_REFERER'];
$_SERVER['HTTP_REFERER'];
global $HTTP_REFERER;
I try assigning them to a var like $thereferer = $HTTP_REFERER;
Nothing is working... and I need this to work. If anyone could please help me out with this... I would so appreciate it.
the cleanest (imho) solution is quite simple: just start a session on each of yoru pages.... and instead of returning the images directly, place them somwhere out your webroot, and have a script like this:
session_start();
if (!array_key_exists('washere', $_SESSION))
{
// they are coming from somewhere else
}
else
{
header(' correct content type etc... ');
file_get_contents( path to the image);
}
Well the problem in my case is that not all users have php pages. they might have a variety such as html, cgi, php, and so on. What i need is to get the referrer (url of page loading my image) with the code in my php page that provides the image.
there is no absolute way. Only if the browser requesting the page provides referrer information, or they supply referral information in the request.
You could make them request the image from a script, whereby if the referral information isn't supplied (in the request uri) you return a bad image of some sort.. or nothing at all, breaking the image on the calling page.