passing variables
Moderator: General Moderators
-
jenjenut233
- Forum Newbie
- Posts: 7
- Joined: Fri Sep 29, 2006 2:23 pm
passing variables
used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:47 pm, edited 1 time in total.
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.
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
used to be a question here.
Last edited by jenjenut233 on Sun Feb 19, 2012 10:47 pm, edited 1 time in total.
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:
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!
}