473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 30491
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Marchello | last post by:
Hi All. I will try to explain my question on following example: Having class CInteger (wraper on 'int' values): class CInteger { public: ..... void SetValueFromPoiner(int *new_value)
3
by: John M | last post by:
I'm lost on somethingthat I feel ought to be simple - getting the contents of a field! The database relates to school students and their subjects. The current record has as its source a query...
8
by: Timo | last post by:
I am trying to get address of myStruct to a string array texts. I am using M$ Visual C++ 6.0 (this is not OS specific question, though, this code should also work on 16 bit embedded compiler ;)). ...
1
by: SamIAm | last post by:
Is there a way to do this without looping through all the nodes using read() I need to return the contents of the reader as a string Thanks S
2
by: pricter | last post by:
Is there a way to get the cell content of a table? For example if I have the below table Parent | Child Mark | Nick Julia | Maria Is there a way to get the contents for example below...
2
by: virgil | last post by:
Need help in getting iframe contents in javascript. Any idea is greatly appreciated.
6
by: DRS.Usenet | last post by:
When I run alert("page contents:" + content.document.documentElement.innerHTML); I am able to pull the content. I see something like this page contents:<head><title>A Title</title>...
1
by: picking4321 | last post by:
I wanna write a script to get the contents of a simple webpage like http://www.craigslist.org/msg i need just text output not html. I search this on google. There are suggestions about using perl...
0
by: Alexnb | last post by:
The trick to this one is that the html looks something like this: <td width="100%" colspan="2"> american, /browse/blue blue , /browse/brick brick , brie, cheddar, cheshire, /browse/churn...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.