How to extract Data from URL 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

User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

How to extract Data from URL bar

Post by NewfieBilko »

Is there anyway to call apon the browser to check the address text in the URL bar? Have it passed to the php?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Do a var_dump($_SERVER); You should see all the 'bits' you want in there.
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

I dont think I understand. Just put that function into a PHP file and it will onload all the bits of information, even the address bar url in the output?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

No, i mean the address in the address bar is made up of a few bits, eg
$_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'], $_SERVER['REQUEST_URI'] etc...
if you do a var_dump($_SERVER); it will show you all the information it has, and the info you want is in there, so just pick out the bits you want, eg if the url is index.php?foo=bar then you might just want the index.php bit without the ?foo=bar bit ... just depends on your needs. But $_SERVER has it all
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

ahhh ok nice, so i can do that, var_dump($SERVER) and will get all info.... thats right, but i want to get the file name, no extensions or anything. If i just want the Filename I will:

Code: Select all

var_dump($_SERVER['REQUEST_URI'])
???????
those 3 additional arrays, they reference the different parts of the url?
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

BTW, how do i just call apon
var_dump($_SERVER['REQUEST_URI'])

to display OUTput to an html?

Do i put it into my php and then call the function var_dump?

I am running smarty with PHP application background and Templates for my Presentation layer. Should i put var_dump($_SERVER['REQUEST_URI'])
in the template or the application.. Im guessing the application, then how do I display the "bits"?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

read the manual and the previous posts. Second link below.
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

yea that was a bit of a stupid question lol sorry
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

hahah ever get mind blocked? then you go outside, or have some sex, or smoke a joint, or have a ciggerette, then it all comes back? lol, yea i came back and im like duhhh obvilsouyy make it a varible to display lol
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Pick which one you want:

Code: Select all

echo $_SERVER['PHP_SELF'];
echo basename($_SERVER['PHP_SELF']);
echo $_SERVER['REQUEST_URI'];
echo __FILE__;
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

neat.


I am going to try and use this, so that I can dynamically pull in what page it is the enduser is viewing, so that I can then have a TREE, or ROOT structure which will be like HOME -> ADMIN-> USERS-> "CURRENT PAGE", calling in the current page as what it is they are on, then based on which page it is just fill in the rooting links...
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

hmmm, i need to make
echo basename($_SERVER['PHP_SELF']);
into a variable so I could use it then.

$mark == basename($_SERVER['PHP_SELF']);

???????? then call mark from the presentation or what not?
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

i've tried:

Code: Select all

$smarty->assign('basename($_SERVER['PHP_SELF'])',$mark);
and then echoing it by refering to it in my html output:
{echo $smarty[mark]} and everything that looks like this but no go.. its ok, ill figure it out im sure lol
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

*smack*
'basename($_SERVER['PHP_SELF'])' remove those outer single quotes, and i'm not sure that's the correct syntax to assign a smarty var, better double check at http://smarty.php.net
User avatar
NewfieBilko
Forum Contributor
Posts: 189
Joined: Sun Jun 06, 2004 6:45 pm
Location: Newfoundland
Contact:

Post by NewfieBilko »

LOL good idea :)
Post Reply