PHP Session Variables

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

I would just like some reference and how to implement session variables in my website...

For example: I want to select a Date, and that date must be automatically carried over to the next page where the database is processed and inputs can be made. Or Select a date, and go to the correct page / fuction corresponding to that date.

Any help would be much appreciated....

THANX...
 
Session Variable

Session variables is easy to implement - All you need to do is either first turn register globals ON on your Apache server, if that is what you are using, alternatively you could use the following php code to initialise the Session variables and register your browser for use with it.

<?php
session_start();
?>

and then to assign a value to the variable, all you need to do is:

<?php
$_SESSION['myDateVariable'] = date('d M Y',mktime());
?>

The 'myDateVariable' part you can rename to anything you wish to call your variable.

Just remember that when you use session_start(), do use it on all pages you use the SESSION variable to unfreeze it.

Hope this helps
 
Thanx DBZ!

I will play around with it a bit and see what I can figure out..!

Thanx...
 
PHTech, I suggest reading: http://www.w3schools.com/php/php_sessions.asp

May I also just quickly interject regarding the register globals comment. I suggest you ensure that this function is turned OFF as it poses a security vulnerability if you're not fully aware of what it's capable of.

If you still have any PHP or SQL questions with regards to what you're intending to achieve, don't hesitate to ask for more help.
 
Yeah, thanks hongong - I almost forgot to add that bit - just make sure you do read up a bit on globals and session variables before you implement them left and right.
 
Top
Sign up to the MyBroadband newsletter
X