943,483 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 31869
  • PHP RSS
Jan 8th, 2005
0

Display URL

Expand Post »
I want to display the URL of a page using PHP.

Basically do this:

<script language="javascript">
document.writeln(document.location);
</script>

with PHP
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
stupidfly is offline Offline
36 posts
since Oct 2004
Jan 8th, 2005
0

Re: Display URL

PHP Syntax (Toggle Plain Text)
  1. $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
  2. echo $url
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Jan 9th, 2005
0

Re: Display URL

The problem is that I used a form with "get". So I need all that information in the URL. when I use that javascript tag, it displays the correct URL, but it I can't insert the javascript into 'href=' like I can with PHP.
Reputation Points: 10
Solved Threads: 0
Light Poster
stupidfly is offline Offline
36 posts
since Oct 2004
Jan 9th, 2005
0

Re: Display URL

ok then well theres two ways to do this then...

PHP Syntax (Toggle Plain Text)
  1. $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
  2. echo $url;

this will always assume there is arguments in the address so u will always see a question mark int the address, a better way of doing this would be to test if there actually was any arguments before just adding the question mark such as in this example:
PHP Syntax (Toggle Plain Text)
  1. $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
  2. if (!empty($_SERVER["QUERY_STRING"]))
  3. $url .= "?".$_SERVER['QUERY_STRING'];
  4.  
  5. echo $url;

i hope this answers any questions you do have
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Jan 11th, 2005
0

Re: Display URL

Thank you! It works wonderfully. Exactly what I wanted. May you live long and prosper.

Godspeed.
Reputation Points: 10
Solved Threads: 0
Light Poster
stupidfly is offline Offline
36 posts
since Oct 2004
Jan 12th, 2005
0

Re: Display URL

:eek:paradox814, you beet me tothe answer again. Good job m8!:p vbmenu_register("postmenu_82884", true);
Reputation Points: 16
Solved Threads: 3
Junior Poster
mikeSQL is offline Offline
196 posts
since Dec 2004
Jan 12th, 2005
0

Re: Display URL

hey i just rememberd one case in which this won't work!!!

if you are usign a secure ssl http session... in which case replace http:// with https:// (notice the s)

ok man, peace out
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Jan 12th, 2005
0

Re: Display URL

No, I'm not. It works fine. Thanks for the heads up though.
Reputation Points: 10
Solved Threads: 0
Light Poster
stupidfly is offline Offline
36 posts
since Oct 2004
Sep 24th, 2011
0
Re: Display URL
how do you do that just with out the file in it... just with the directory in it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ragstergurr2122 is offline Offline
1 posts
since Sep 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: I am learning MySQL, PHP, Databases, etc. - Help with site please?
Next Thread in PHP Forum Timeline: class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC