Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Query String Variables in PHP Image

    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.)
    If you're reading this, it may already be too late!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

    Edit.
    Oh yeah. I guess you can always get the HTTP_REFERER of the request. Thats not overly reliable though...
    Last edited by Fou-Lu; 12-28-2007 at 04:24 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    If you're reading this, it may already be too late!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.)
    Last edited by Digger3000; 12-28-2007 at 04:34 AM. Reason: Clarifying
    If you're reading this, it may already be too late!

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Let me see if I can explain this. I'm embedding the image on the remote site, but I don't have the ability to use PHP or even javascript on that site. So if=s there any way, using just HTML, that I can add the full URL to the end of the image? Like <img src="img.jpg?url=(whatever the url is)" /> (I know, probably not.)
    If you're reading this, it may already be too late!

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •