Page 1 of 1

Trying to get url of page my image is displayed on. Ideas???

Posted: Thu Feb 03, 2005 11:21 pm
by idotcom
Hi there.

I am trying to get the url of the page that is loading my images. I allow people to display images on their pages but loading them from my server.

example

http://www.somedomain.com/thispage.html
This page loads my image like this


<img src="http://www.mydomain.com/images/provide_ ... simage.gif">


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.

Thanks in advance! :lol:

Posted: Thu Feb 03, 2005 11:29 pm
by feyd
referrer information is optionally sent, there is no guaranteed way without the URL encoding the information somehow.

Posted: Fri Feb 04, 2005 6:15 am
by timvw
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:

somepage.php
session_start();
$_SESSION['washere'] = 'ok';

<img src="image.php?path=image_id" />


image.php

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);
}

Posted: Fri Feb 04, 2005 6:24 am
by anjanesh
How abt getting the IP by $_SERVER['REMOTE_ADDR'] ?

Posted: Fri Feb 04, 2005 8:12 am
by feyd
REMOTE_ADDR has nothing to do with referrer.

Posted: Fri Feb 04, 2005 9:31 am
by PrObLeM
REMOTE_ADDR only gets the ip of the user that is viewing the image not the server it is on.

Posted: Fri Feb 04, 2005 3:20 pm
by idotcom
Thanks guys for your input!!!

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.

I cant rely on others pages to provide the data.

there must be a way.... :?

One of you experts know how :D

Thanks again fellers!

Posted: Fri Feb 04, 2005 3:29 pm
by feyd
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.