[SOLVED] Getting the URL from address bar

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
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Getting the URL from address bar

Post 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.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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()
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look at the output of

Code: Select all

<?php

print_r($_SERVER);

?>
the information you want is contained in there.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
crabyars
Forum Commoner
Posts: 37
Joined: Thu Jun 17, 2004 8:24 pm

Post 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?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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>
crabyars
Forum Commoner
Posts: 37
Joined: Thu Jun 17, 2004 8:24 pm

Post 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.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Ok, thanks people, I have managed to get it working now.

Thanks.
Post Reply