View Full Version : Resolved Getting current URL in PHP image

03-15-2010, 11:50 PM
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?


03-16-2010, 12:40 AM
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

03-16-2010, 03:35 AM
(Cookyx) site belongs to me.

03-16-2010, 01:27 PM
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.

03-16-2010, 03:16 PM
For example, let's say I have the image put here.

Well, the referring url would be

Get it?

03-16-2010, 05:19 PM
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.

03-16-2010, 07:21 PM
Is the address in the HTTP_REFERER on the $_SERVER superglobal?

03-16-2010, 11:19 PM
Is the address in the HTTP_REFERER on the $_SERVER superglobal?

How do I check that? phpinfo?

03-17-2010, 12:19 AM
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.

03-17-2010, 12:25 AM

Didn't seem to find it. :\


doing this:


echo "Test " + $hi;


will return a 0. Just a simple zero on a page.

03-17-2010, 12:50 AM
Hmm, works ok for me, this is what I see on the h.php page for you:

_SERVER["HTTP_REFERER"] http://www.codingforums.com/showthread.php?t=191582

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.

Hah, too much java for you mate, you can't add a string in PHP ;)
That explains the mystery of the 0 :D

03-17-2010, 01:39 AM
Ahhhhhhh. You right man! Too much Java!



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:

$text2 = "None";
$text2 = $_SERVER['HTTP_REFERER'];

But, as guessed, didn't work.

03-17-2010, 02:27 AM

03-17-2010, 02:27 AM
Oh, rite rite. I keep forgetting these things. :-P