Page 1 of 1

Getting the URL from address bar

Posted: Fri Jun 18, 2004 2:25 pm
by Archy
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.

Posted: Fri Jun 18, 2004 2:43 pm
by dull1554
why dont you give searching the foeums a try, i know there have been a bunch of topics about such things.

if you cant find a topic answering your question then have a look at the manual there is a pre defined function to do exactly what you wand.

parse_url()

Posted: Fri Jun 18, 2004 3:20 pm
by feyd
look at the output of

Code: Select all

<?php

print_r($_SERVER);

?>
the information you want is contained in there.

Posted: Fri Jun 18, 2004 5:21 pm
by John Cartwright
$_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

Posted: Fri Jun 18, 2004 5:48 pm
by crabyars
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
I don't understand your question. You mean you want to mask the "?=whatever" into a plain URL?

Posted: Fri Jun 18, 2004 6:06 pm
by tim
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
if u read what he asked, you would notice your answer is not what he wants lol.

print_r($_SERVER); would reveal your answer =]

as stated

Posted: Fri Jun 18, 2004 6:56 pm
by dethron
May be this example helps you.

Code: Select all

<html>
<head>
<script type="text/javascript">
function currentLocation()
&#123;
alert(location)
&#125;
</script>
</head>
<body>
<form action="submit.php">
<input type="button" onclick="currentLocation()"
value="Current URL">
</form>
</body>
</html>

Posted: Fri Jun 18, 2004 7:17 pm
by crabyars
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.

Posted: Sat Jun 19, 2004 3:16 am
by Archy
Ok, thanks people, I have managed to get it working now.

Thanks.