View Full Version : Query String Variables in PHP Image
12-28-2007, 05:02 AM
Let's say I have a PHP scripts that generates an image. Is there any way that, from that PHP script, I can get the address of the website that the image is on? (If that makes any sense.)
12-28-2007, 05:22 AM
Do you need to do this for an actual tracking image, or are you trying to prevent hotlinking? Preventing is the easiest solution for it, but I'm not sure about tracking (I'm not a huge image generator myself), but someone might have a more specific option for tracking for you available.
Oh yeah. I guess you can always get the HTTP_REFERER of the request. Thats not overly reliable though...
12-28-2007, 05:24 AM
Basically, if the image I'm generating is embedded onto "example.com" I want the image to be able to say "You're on example.com" for example. I also want the image to access any $_GET variables in the url.
12-28-2007, 05:28 AM
Not possible though standard script generation.
I'm assuming that example.com is remote, and the image is linked via <img> tags or as a part of a css background. Keep in mind, that the _GET you would receive is whatever is attached to the actual image, and that would probably be nothing. You cannot retrieve the get requests on a remote site through your image as it is preprocessed by your server, and then sent to be displayed on their server. If its a cooperative measure, the remote programmer could append the get to the end of the image call so that the remote server (this would be your server) can also interpret the get request.
Is there a reason why you are looking at doing something like this?
12-28-2007, 05:31 AM
There is, but I don't know how I'd go about explaining it. Well, is there any way to append the end of the image with the address of the remote site, "example.com"? (Without using PHP.)
12-28-2007, 05:40 AM
Yep, thats what I mean by using cooperation from the remote programmer:
<img src="img.php?addr=http://www.example.com" alt="" />
That is the only standard way I can think of to pass information to the script from the remote call, which means that you cannot program it within the script itself (except as I mentioned, using HTTP_REFERER and a database).
12-28-2007, 06:01 AM
12-28-2007, 06:12 AM
Not you nope, you gotta leave that to the remote.
Like I said though, you can get the referrer of the site from the server superglobal, although it is not really reliable. That means you can (unreliably) determine where the request is coming from, but it is the best bet for a non-controllable environment.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.