...

View Full Version : Resolved Getting current URL in PHP image



UrbanTwitch
03-15-2010, 11:50 PM
I am trying to get the current URL the image is posted on. For example, take this:

http://cookyx.com/test/1.png
(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.

mlseim
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

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

mlseim
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.

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

Well, the referring url would be

http://www.codingforums.com/showthread.php?t=191582
Get it?

mlseim
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.

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

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

How do I check that? phpinfo?

Fou-Lu
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.

UrbanTwitch
03-17-2010, 12:25 AM
http://cookyx.com/h.php

Didn't seem to find it. :\

------
edit:

doing this:

<?php

$hi = $_SERVER['HTTP_REFERER'];
echo "Test " + $hi;

?>

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

Fou-Lu
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

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


<?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:

if (!$_SERVER['HTTP_REFERER']) {
$text2 = "None";
}else{
$text2 = $_SERVER['HTTP_REFERER'];
}

But, as guessed, didn't work.

MattF
03-17-2010, 02:27 AM
isset.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum