Passing variables

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
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Passing variables

Post by mikusan »

Could someone take the time to explain to me how to pass variables from file to file *.php

you know how when you click on a specific link... the request is sent in the header in the form... sitename.com/index.php?something=23&fields=true...

how to make those but most importantly how to retrieve them...

thx abunch
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

I read the post above... but thought this didn;t quite apply or perhaps i didn;t understand the other one clearly enough
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

To get information that is passed along in a query string, use the $_GET global.

For instance, in a string like:

http://www.yoursite.com/index.php?monkey=Bob&cat=Tom

where Bob defines the variable monkey and Tom defines the variable cat, you would use:

Code: Select all

$_GET['monkey'];  // This would translate to the value "Bob."
$_GET['cat']; //This would in turn translate to the value "Tom."
To create query strings, simply use the normal URL format followed by a "?" (question mark symbol). For every variable you list after the first one, you the "&" (ampersand symbol) to denote separations.

Note that you can set the values for variables as variables themselves.

For instance, in the original string, if you want to set the value of 'monkey' as the variable '$monkeyname' and the value of the variable 'cat' as '$catname', do the following (assuming you already have these variables set in your script):

http://www.yoursite.com/index.php?monke ... t=$catname

Very simple stuff! Enjoy!
Post Reply