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
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

passing variables

Post by jenjenut233 »

used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:47 pm, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

sessions are what you're looking for.

have a look here
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

I guess you can use session or cookie

session keeps the variables in $_SESSION array which is accessile on all the pages containing session_start(); function or in all pages even they dont contain session_start() but if s session_autostart is 1 into the php.ini file.

for example you can put session_start(); in the first line of the php script and then use $_SESSION['name'] = "Jen";

then create new page, put session_start(); on top and do echo $_SESSION['name'];

The session identifier is saved in a cookie in the client computer or in the URL depending on the php config settings, so if it's set to save as cookie you should have enabled accepting cookies in browser.


The other option is to keep variables into cookies by using set_cookie("name","Jen");

and print the value by using echo $_COOKIE['name'];

I think session is better.
jenjenut233
Forum Newbie
Posts: 7
Joined: Fri Sep 29, 2006 2:23 pm

Post by jenjenut233 »

used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:47 pm, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you can set session variables on any of the pages you want. The session variables are handled in an array so you can have as many as you'd like.

ex:

Code: Select all

// set your start time when they first arrive
$_SESSION['start'] = time();

// check to make sure that the time has not exceeded their allotted amount.
if($_SESSION['start'] > (time() + 3600)
{
  //oops! time's up!
}
Post Reply