[SOLVED] Getting the URL from address bar
Moderator: General Moderators
Getting the URL from address bar
Hi, I am having a few problems trying to get the URL of the page that the user is on at the moment. I have been on the PHP.net site, and also searched google for answers, but with no success.
All I really need is a short code, to try and get the URL from the address bar, so I can then show a page depending on the URL. I do not want to use .php?id=$id and such, but if no one can help me, then I may be forced to go down this route.
Thanks.
All I really need is a short code, to try and get the URL from the address bar, so I can then show a page depending on the URL. I do not want to use .php?id=$id and such, but if no one can help me, then I may be forced to go down this route.
Thanks.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
look at the output of
the information you want is contained in there.
Code: Select all
<?php
print_r($_SERVER);
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
$_POST to check info from form
echo $_POST["info"]; // will output a submitted field called info
$_GET to get info from url (http://www.domain.com/index.php?x=4 )
echo $_GET["x"]; //will output 4
$_REQUEST["var"] is either of them
echo $_POST["info"]; // will output a submitted field called info
$_GET to get info from url (http://www.domain.com/index.php?x=4 )
echo $_GET["x"]; //will output 4
$_REQUEST["var"] is either of them
if u read what he asked, you would notice your answer is not what he wants lol.Phenom wrote:$_POST to check info from form
echo $_POST["info"]; // will output a submitted field called info
$_GET to get info from url (http://www.domain.com/index.php?x=4 )
echo $_GET["x"]; //will output 4
$_REQUEST["var"] is either of them
print_r($_SERVER); would reveal your answer =]
as stated
May be this example helps you.
Code: Select all
<html>
<head>
<script type="text/javascript">
function currentLocation()
{
alert(location)
}
</script>
</head>
<body>
<form action="submit.php">
<input type="button" onclick="currentLocation()"
value="Current URL">
</form>
</body>
</html>Wow this thread is nuts
I think I understand the request now. You want to get the current URL of the page being processed.
Try looking at the variable $_SERVER["SCRIPT_NAME"]
Here is a small php code snippetthat shows how to get just the name of the file without the full url.
Try looking at the variable $_SERVER["SCRIPT_NAME"]
Here is a small php code snippetthat shows how to get just the name of the file without the full url.