![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Senior Coder ![]() Join Date: Jul 2005
Location: UK
Posts: 1,051
Thanks: 6
Thanked 13 Times in 13 Posts
![]() |
Retrieving Full URL
I found this piece of code that will do it
http://dev.kanngard.net/Permalinks/I...507183447.html However this seems quite long-winded for what I imagined would be quite a basic function. Is there a shorter way to do this (something akin to $_SERVER[PHP_SELF] but for the full URL)? |
|
|
|
|
|
PM User | #3 | |
|
Regular Coder ![]() Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 824
Thanks: 2
Thanked 1 Time in 1 Post
![]() |
Quote:
PHP Code:
__________________
Check out TV Shack, and get entertained! |
|
|
|
|
|
|
PM User | #5 | |
|
Regular Coder ![]() Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 824
Thanks: 2
Thanked 1 Time in 1 Post
![]() |
Quote:
Code:
<form name="form1" method="post" action="<?php echo fetch_url(); ?>"> PHP Code:
__________________
Check out TV Shack, and get entertained! |
|
|
|
|
|
|
PM User | #6 | |
|
Senior Coder ![]() Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
![]() |
Quote:
Both show the directories when concatinated within a string containing HTTP_HOST, PHP_SELF and QUERY_STRING to echo the full url for the current page. What are the supposed differences and in what circumstances do they become evident? |
|
|
|
|
|
|
PM User | #7 |
|
Senior Coder ![]() ![]() Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
djdykes:
$_SERVER['REQUEST_URI'] shows only the path to the file, whereas $_SERVER['PHP_SELF'] gives the path to the file as well as the query string. You should be able to use this: PHP Code:
__________________
PHP Weekly - A PHP Developers Resource PHP 5.1.4 and Ruby on Rails web hosting Moderator of PHP and Work offers and Requests Install Apache/PHP/MySQL (by marek_mar) | TinyPlugin Architecture |
|
|
|
|
|
PM User | #8 | |
|
Senior Coder ![]() Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
![]() |
Quote:
Perhaps it's a version thing. I'm running PHP 5.01. |
|
|
|
|
|
|
PM User | #9 |
|
Regular Coder ![]() Join Date: Feb 2004
Location: Cornwall, UK
Posts: 535
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
What was wrong with the version you linked to? It even gets the protocol and port number by the looks of it. It doesn't matter if it's a little complex when it's tucked away in a function
![]() Edit: And I'm pretty sure PHP_SELF doesn't include the query string in any version of PHP. Last edited by trib4lmaniac; 12-16-2005 at 04:44 PM.. |
|
|
|
|
|
PM User | #10 |
|
Regular Coder ![]() Join Date: Apr 2004
Location: Birmingham, MI
Posts: 131
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
$_SERVER['PHP_SELF'] will give you the EXECUTING script, so if you are using mod_rewrite, you may have some problems.
$_SERVER['REQUEST_URI'] gives the actual request (as entered in the address bar)
__________________
Validate: https://addons.mozilla.org/en-US/firefox/addon/249 |
|
|
|
|
|
PM User | #11 | |
|
Regular Coder ![]() Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 824
Thanks: 2
Thanked 1 Time in 1 Post
![]() |
Quote:
__________________
Check out TV Shack, and get entertained! |
|
|
|
|
|
|
PM User | #12 |
|
Senior Coder ![]() Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Indeed. Example from a phpinfo.php:
_SERVER["QUERY_STRING"] query=string&query2=string2 _SERVER["REQUEST_URI"] /phpinfo.php?query=string&query2=string2 _SERVER["SCRIPT_NAME"] /phpinfo.php
__________________
"$question = ( to() ) ? be() : ~be();" |
|
|
|
|
|
PM User | #13 | |
|
Regular Coder ![]() Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 824
Thanks: 2
Thanked 1 Time in 1 Post
![]() |
Quote:
_SERVER['HTTP_HOST'] => ameirkanmetz.rave5.com _SERVER['QUERY_STRING'] => a=b&b=b _SERVER['REQUEST_URI'] => /blah/demo/test/what.php?a=b&b=b _SERVER['SCRIPT_NAME'] => /what.php
__________________
Check out TV Shack, and get entertained! |
|
|
|
|
|
|
PM User | #14 |
|
New to the CF scene Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
hii thanks for the above info,
but its not satisfying my requirement what i need to trace is not ust url with query strin but i also need to trace #href i.e. if my url is http://jigishthakar.com/?p=2#cid then till http://jigishthakar.com/?p=2 ur code works fine but now how to trace #cid ? |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|