Reply
how to get the url variable..?
Old 10-04-2006, 11:28 AM how to get the url variable..?
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
I can't figure out how to get a url variable:

If I want to assign a variable with infomation passed with the url what array do I use to access this information?

HTML Code:
"http://www.mysite.com/page.php?stuff=qwerty"
PHP Code:

<?php
$urlstuff 
$_what goes_here;
?>
Thanks for any help,

Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
When You Register, These Ads Go Away!
Old 10-04-2006, 02:26 PM Re: how to get the url variable..?
mad_willsy's Avatar
Super Spam Talker

Posts: 774
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
The information passed in the URL is assigned as a variable:

On your example...

PHP Code:
<?php echo $stuff ?>
Would print..

qwerty

Talkupation apreciated :P
__________________
Wont :P
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 10-04-2006, 02:42 PM Re: how to get the url variable..?
Experienced Talker

Posts: 40
Name: Jeff
Location: IL
Lets say the URL is mysite.com/index.php?foo=bar
Then add a $ to foo so it is $foo.
PHP Code:
 <? echo"$foo"?>
It will display
bar

Understand?
Scout is offline
Reply With Quote
View Public Profile Visit Scout's homepage!
 
Old 10-04-2006, 02:54 PM Re: how to get the url variable..?
Ultra Talker

Posts: 481
Umm... both mad_willsy and Scout are correct, ONLY if you have register_globals set to on, which is a security risk.

Parameters passed in the URL are called GET parameters and are available through either the $_GET array or the $_REQUEST array.

In your case, you can do:
$urlstuff = $_GET['stuff'];

and then $urlstuff will be equal to 'qwerty'.

To add to what Scout said: you don't need to wrap a variable in quotes to print it and if you use single quotes, it won't 'interpret' the variable at all. So, again, in your case:

$urlstuff = $_GET['stuff'];
print "$urlstuff"; // prints qwerty
print $urlstuff; // also prints qwerty
print '$urlstuff'; // prints $urlstuff
__________________
Free PHP Obfuscator
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 10-05-2006, 01:02 AM Re: how to get the url variable..?
jito's Avatar
MY LIFE IS 'i' LIFE

Posts: 551
Name: surajit ray
Location: inside the heart of my friends
$urlstuff = $_GET['stuff'];
and to get the the whole query string:
$_SERVER['QUERY_STRING']
__________________
Think+, work +, but not HIV + :)
jito is offline
Reply With Quote
View Public Profile
 
Old 10-05-2006, 06:07 AM Re: how to get the url variable..?
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
Thanks All, TwistmyArm, it worked. I tried that before but couldn't get it to work. I had the syntax a lilttle incorrect. You set me straight. I appreciate the help.

I learned something from all the posts. Now I'm back on the straight and narrows...
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Reply     « Reply to how to get the url variable..?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15105 seconds with 12 queries