url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

url

Post by nincha »

any way to get the current url and set it to a variable?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

If you need the whole url, including url parameters, you can use JavaScript.

Specifically, window.location.search holds the whole url.

<script language="JavaScript">
document.write('The URL is' + window.location.search);
</script>
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

didnt seem to work
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

<script language="JavaScript">
document.write('The URL is' + window.location.href);
</script>

window.location.search actually only returns the url parameters.
Last edited by microthick on Mon Dec 29, 2003 6:12 pm, edited 2 times in total.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I take it you want this done in PHP?

Code: Select all

<?php

$page = $_SERVER["PHP_SELF"];
$uri = $_SERVER["REQUEST_URI"];

echo "{$page}<hr />{$uri}";

?>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Gen-ik wrote:I take it you want this done in PHP?

Code: Select all

<?php

$page = $_SERVER["PHP_SELF"];
$uri = $_SERVER["REQUEST_URI"];

echo "{$page}<hr />{$uri}";

?>
I've never used REQUEST_URI. Does it return the whole url, including url parameters?
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

thnx alot u guys!
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

microthick wrote:
Gen-ik wrote:I take it you want this done in PHP?

Code: Select all

<?php

$page = $_SERVER["PHP_SELF"];
$uri = $_SERVER["REQUEST_URI"];

echo "{$page}<hr />{$uri}";

?>
I've never used REQUEST_URI. Does it return the whole url, including url parameters?
Yep it sure does :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

If you run the following script:

Code: Select all

<?php
echo '<pre>';
    print_r($_SERVER);
echo '</pre>';
?>
You'll discover a few more that work similar.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

mMm.......what's the difference between URI and URL? Uniform Resource Locator and Uniform Resource ur.......Inspector?

*hangs head in shame*

-Nay
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yup. They're pretty much the same thing.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post by Derfel Cadarn »

Hey Nay, now you've disappointed me! :lol:

Read this uri-clarification, there are URN's too! Great! 8O
I'm waiting for the URQ's....
Post Reply