469,266 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

Getting address bar contents with PHP

How do I get the contents of the browser address bar with PHP - assuming it
is possible?

In javascript it is done with: unescape(window.location.pathname), but is
there a php equivalent?

Thanks

Hamilton
Jul 17 '05 #1
10 29790
would SERVER['PHP_SELF'] do the job?

Jul 17 '05 #2
Spidah wrote:
How do I get the contents of the browser address bar with PHP - assuming it
is possible?

In javascript it is done with: unescape(window.location.pathname), but is
there a php equivalent?


For this url -> http://www.example.com/path/to/location.php?x=one&y=two

#v+
<?php
$fulluri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo $fulluri;
?>
#v-

will output
http://www.example.com/path/to/location.php?x=one&y=two
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
Matthew Robinson a écrit le 21/01/2004 :
would SERVER['PHP_SELF'] do the job?


No
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] should be prefered.
Jul 17 '05 #4
$_SERVER['HTTP_HOST'] is better actually, as it gives you the port number as
well.

Uzytkownik "Jedi121" <je*********@free.fr.Removethis> napisal w wiadomosci
news:me********************************@free.fr.Re movethis...
Matthew Robinson a écrit le 21/01/2004 :
would SERVER['PHP_SELF'] do the job?


No
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] should be prefered.

Jul 17 '05 #5
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:k6********************@comcast.com...
$_SERVER['HTTP_HOST'] is better actually, as it gives you the port number as well.

Uzytkownik "Jedi121" <je*********@free.fr.Removethis> napisal w wiadomosci
news:me********************************@free.fr.Re movethis...
Matthew Robinson a écrit le 21/01/2004 :
would SERVER['PHP_SELF'] do the job?


No
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] should be prefered.


It wouldn't work in a frameset though. Least not that I could see.

--
Chris Mosser

Jul 17 '05 #6
$_SERVER['REQUEST_URI'] is rteturning nothing here. Any idea why that might
be?

Hamilton

"Pedro Graca" <he****@hotpop.com> wrote in message
news:bu************@ID-203069.news.uni-berlin.de...
Spidah wrote:
How do I get the contents of the browser address bar with PHP - assuming it is possible?

In javascript it is done with: unescape(window.location.pathname), but is there a php equivalent?


For this url -> http://www.example.com/path/to/location.php?x=one&y=two

#v+
<?php
$fulluri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo $fulluri;
?>
#v-

will output
http://www.example.com/path/to/location.php?x=one&y=two
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--

Jul 17 '05 #7
I have however managed to get what I need with:

$temp = "http://" .
$_SERVER['SERVER_NAME']."/".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'
];
echo $temp;

Hamilton

"Spidah" <h.*********@eggstra.co.nz> wrote in message
news:7i********************@news.xtra.co.nz...
$_SERVER['REQUEST_URI'] is rteturning nothing here. Any idea why that might be?

Hamilton

"Pedro Graca" <he****@hotpop.com> wrote in message
news:bu************@ID-203069.news.uni-berlin.de...
Spidah wrote:
How do I get the contents of the browser address bar with PHP -
assuming
it is possible?

In javascript it is done with: unescape(window.location.pathname), but is there a php equivalent?


For this url -> http://www.example.com/path/to/location.php?x=one&y=two

#v+
<?php
$fulluri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; echo $fulluri;
?>
#v-

will output
http://www.example.com/path/to/location.php?x=one&y=two
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--


Jul 17 '05 #8
On Tue, 20 Jan 2004 16:40:42 -0800, "Chris Mosser"
<cmosser_at_comcast_dot_net> wrote:
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:k6********************@comcast.com...
$_SERVER['HTTP_HOST'] is better actually, as it gives you the port number

as
well.

Uzytkownik "Jedi121" <je*********@free.fr.Removethis> napisal w wiadomosci
news:me********************************@free.fr.Re movethis...
> Matthew Robinson a écrit le 21/01/2004 :
> > would SERVER['PHP_SELF'] do the job?
>
> No
> $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] should be prefered.
>
>


It wouldn't work in a frameset though. Least not that I could see.


Or if the URL contained a fragment identifier:
http://www.example.com/foo.php#bar

You won't get the "#bar"

--
David ( @priz.co.uk )
Jul 17 '05 #9
Regarding this well-known quote, often attributed to Chris Mosser's famous
"Tue, 20 Jan 2004 16:40:42 -0800" speech:
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:k6********************@comcast.com...
$_SERVER['HTTP_HOST'] is better actually, as it gives you the port number

as
well.

Uzytkownik "Jedi121" <je*********@free.fr.Removethis> napisal w wiadomosci
news:me********************************@free.fr.Re movethis...
Matthew Robinson a écrit le 21/01/2004 :
> would SERVER['PHP_SELF'] do the job?

No
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] should be prefered.


It wouldn't work in a frameset though. Least not that I could see.


Framesets are totally client-side. You'd have to use JavaScript to pass the
value to PHP, then.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #10
Matthew Robinson wrote:
would SERVER['PHP_SELF'] do the job?


Not always.

Consider the URL http://talrias.net/

I have a file called index.php which is the default file served.
$_SERVER['PHP_SELF'] would return '/index.php' while
$_SERVER['REQUEST_URI'] would return '/'.

Also, if I am using something like mod_rewrite PHP_SELF is completely
different to REQUEST_URI.

Since the original poster said they wanted the contents of the URI bar
they should be using REQUEST_URI rather than PHP_SELF. :)

Chris

--
Chris Jenkinson

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Marchello | last post: by
2 posts views Thread by pricter | last post: by
6 posts views Thread by DRS.Usenet | last post: by
reply views Thread by Alexnb | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.