Display URL

Reply

Join Date: Oct 2004
Posts: 36
Reputation: stupidfly is an unknown quantity at this point 
Solved Threads: 0
stupidfly stupidfly is offline Offline
Light Poster

Display URL

 
0
  #1
Jan 8th, 2005
I want to display the URL of a page using PHP.

Basically do this:

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

with PHP
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Display URL

 
0
  #2
Jan 8th, 2005
  1. $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
  2. echo $url
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 36
Reputation: stupidfly is an unknown quantity at this point 
Solved Threads: 0
stupidfly stupidfly is offline Offline
Light Poster

Re: Display URL

 
0
  #3
Jan 9th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Display URL

 
0
  #4
Jan 9th, 2005
ok then well theres two ways to do this then...

  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:
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 36
Reputation: stupidfly is an unknown quantity at this point 
Solved Threads: 0
stupidfly stupidfly is offline Offline
Light Poster

Re: Display URL

 
0
  #5
Jan 11th, 2005
Thank you! It works wonderfully. Exactly what I wanted. May you live long and prosper.

Godspeed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 196
Reputation: mikeSQL is an unknown quantity at this point 
Solved Threads: 3
mikeSQL's Avatar
mikeSQL mikeSQL is offline Offline
Junior Poster

Re: Display URL

 
0
  #6
Jan 12th, 2005
:eek:paradox814, you beet me tothe answer again. Good job m8!:p vbmenu_register("postmenu_82884", true);
dynastyCODERS#1 when it comes to Programming Tutorials, Database designs and discussions, Operating Systems, you name it, check us out and drop us a line to tell us your opinions on any and everything in mind!;)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Display URL

 
0
  #7
Jan 12th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 36
Reputation: stupidfly is an unknown quantity at this point 
Solved Threads: 0
stupidfly stupidfly is offline Offline
Light Poster

Re: Display URL

 
0
  #8
Jan 12th, 2005
No, I'm not. It works fine. Thanks for the heads up though.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC