imagecreatefromjpeg() dynamic page URL


I am currently writing a script that will call a dynamic image and write the URL of the page that calls the image ("")

Something like this is what I have so far:

$url = sprintf("%s%s%s","http://",$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']);

$image = "authbackimg.jpeg"; 
$im = imagecreatefromjpeg($image); 
$tc  = ImageColorAllocate ($im, 0, 0, 0); 

ImageString($im, 3, 148, 2, "text text text", $tc); 
ImageString($im, 2, 148, 15, "more text", $tc); 
ImageString($im, 2, 148, 25, "$url", $tc); 
ImageString($im, 2, 148, 35, "even more text", $tc); 
ImageString($im, 2, 148, 45, "and the last text", $tc); 
header("Content-Type: image/jpeg"); 
ImageDestroy ($im); 

and in I have:

<img src="authimage.php" />

So when the image is called from the page, I want $url to say “” , indicating the page that it is called on.

However, instead of outputting the location of the page that calls the image, it outputs the location of the image itself.

One thing I have tried on http://localhost/ that worked was $_SERVER[‘HTTP_REFERER’]. Because the page that calls the image would be the referer. However, when I upload the page to my online server, HTTP_REFERER has no value. (Could this be because http://localhost/ is Windows server, and online ls Linux? They both run Apache.)

If anyone could help me it would be GREATLY appreciated. Thank you.



If you’re calling the image from, i.e. the address you want texted onto the image, then pass it in a $_GET variable to the image script. That way, the image script will receive the info and you can write it via imagefttext or whatever.