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 14 of 14
  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    Getting current URL in PHP image

    I am trying to get the current URL the image is posted on. For example, take this:


    (or http://cookyx.com/sig.php?id=1)

    Its not getting the current URL on THIS page rather the URL the image is hosted on. How do I fix/do this?

    Thanks.
    Last edited by UrbanTwitch; 03-17-2010 at 01:37 AM.
    Formerly MysticScript

    6+ years club

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    If that site does not belong to you, they can display (and hide the location) of any image
    they want using PHP, and you will never know where the image is really stored.
    That's the point of using PHP to "hide" the actual location of a file.

    If the site belongs to you, that's a different story.
    You can program the PHP to "show" whatever information you want.

    I do that all the time with PDF files. I can serve the file using PHP and hide it's real location:
    Example: http://www.catpin.com/pf.php?file=8uj321

  • #3
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    (Cookyx) site belongs to me.
    Formerly MysticScript

    6+ years club

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    So you want it so that if a visitor right-clicks on your graphic,
    they get the URL of the graphic and not the PHP link?

    I guess I don't understand the question.

  • #5
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    For example, let's say I have the image put here.

    Well, the referring url would be
    Code:
    http://www.codingforums.com/showthread.php?t=191582
    Get it?
    Formerly MysticScript

    6+ years club

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I feel like a dope for not understanding what the purpose is,
    or why someone would need to know what the URL is for an image.
    I apologize that I just can't figure out what you're looking for.

    Maybe someone else can see it.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Is the address in the HTTP_REFERER on the $_SERVER superglobal?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    Is the address in the HTTP_REFERER on the $_SERVER superglobal?
    How do I check that? phpinfo?
    Formerly MysticScript

    6+ years club

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by UrbanTwitch View Post
    How do I check that? phpinfo?
    PHPInfo will show it yes. Otherwise, just check the $_SERVER['HTTP_REFERER'] or dump the entire $_SERVER superglobal to see whats in it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    http://cookyx.com/h.php

    Didn't seem to find it. :\

    ------
    edit:

    doing this:
    Code:
    <?php 
    
    $hi = $_SERVER['HTTP_REFERER'];
    echo "Test " + $hi;
    
    ?>
    will return a 0. Just a simple zero on a page.
    Formerly MysticScript

    6+ years club

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Hmm, works ok for me, this is what I see on the h.php page for you:

    _SERVER["HTTP_REFERER"] Getting current URL in PHP image

    Which appears to be correct (I presume that that threadid is correct). Note that HTTP_REFERER is not a guarenteed offset; its just commonly set. Potentially you have no referer, so try to attach from another referring page. Also, it may not be set if its you're home page for example. This you can certainly trap, if you cannot find an HTTP_REFERER offset, just give you're site instead.

    Edit:
    Hah, too much java for you mate, you can't add a string in PHP
    That explains the mystery of the 0
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    UrbanTwitch (03-17-2010)

  • #12
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Ahhhhhhh. You right man! Too much Java!

    Code:
    <?php 
    
    $ref = $_SERVER['HTTP_REFERER'];
    
    echo "<font face='Verdana' size='3'><b>Referrer of this page  = $ref </b>";
    
    ?>
    Such a simple solution! Cheers. :P
    -----------------------------------

    Hmm, how can you tell if there is NO HTTP Referrer? Like someone directly goes to it...

    I thought up of something like:
    Code:
    if (!$_SERVER['HTTP_REFERER']) {
        $text2 = "None";
    }else{
    $text2 = $_SERVER['HTTP_REFERER'];
    }
    But, as guessed, didn't work.
    Last edited by UrbanTwitch; 03-17-2010 at 01:27 AM.
    Formerly MysticScript

    6+ years club

  • #13
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    isset.

  • Users who have thanked MattF for this post:

    UrbanTwitch (03-17-2010)

  • #14
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    Oh, rite rite. I keep forgetting these things. :-P
    Formerly MysticScript

    6+ years club


  •  

    Posting Permissions

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