LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2006, 07:14 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
PHP: How to find my url?


Is there a way to find the URL of a php doc from within the php doc without going through a post or get step? I know I can use the global $HTTP_REFERER, but that only works once data has been posted via a form - not if I just land on the page by typing it in.
 
Old 02-08-2006, 07:40 PM   #2
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 32
So you want the URL of the current page, right? Just check the documentation for the $_SERVER superglobal. You can use $_SERVER['REQUEST_URI'], $_SERVER['PHP_SELF'], and several other as well. Of course, those only give you the path, not the hostname. For that, you need $_SERVER['HTTP_HOST'].
 
Old 02-08-2006, 07:40 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Got it ... to a degree ...

$REQUEST_URI is the full path to the php doc, including get args. Some assembly will give back the full URL including get args.

If there's a better solution, feel free to chime in.
 
Old 02-08-2006, 07:42 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
hehe... posted at the same time.

Thanks for the page on $_SERVER - hadn't seen that yet.
 
Old 02-08-2006, 08:49 PM   #5
airswit
Member
 
Registered: Dec 2005
Distribution: Fedora 4
Posts: 89

Rep: Reputation: 15
www.php.net is your friend..i practically live there...hehe. the best way i have found to get the correct items for this is to have a page display phpinfo(). if the page containing <?php phpinfo();?> is called say, info.php for example. call the page by typing, in url: http://yourpage.com/info.php?you=rock&php=iscool, and then you can see the difference between say PHP_SELF and REQUEST_URI, and you can see all of the other attributes of $_SERVER and the like
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP URL Arguments cb8100 Programming 2 03-26-2005 02:39 AM
Getting the url with PHP linux_pioneer Linux - General 2 06-20-2004 02:08 PM
# URL variable in PHP fatman Programming 1 06-04-2004 10:42 PM
PHP Url? HappyDude Programming 2 09-20-2003 04:20 PM
PHP Session -- Url contains ?<NAME>=<ID> tomgun6 Programming 0 03-02-2003 11:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration