PHP Sessions Help

Permabanned
Joined
13 Nov 2006
Posts
5,798
Hi guys. I'm basically storing a few simple variables on my site with sessions. Is there anything else apart from session_start() and actually storing the vaiables that I need to know about.

I assume a unique id gets generated for every visitor automatically?
 
session_start() looks to see if the user already has a session through a cookie or URL. If not it generates an ID and sets a cookie (if possible/allowed) otherwise appends the session ID to each link in the page.

You can get/set the session ID with session_id if you need it to be portable across domains or similar.

Use the $_SESSION array to store variables.

HTH :).
 
session_start(); // Use that on every page that involves a session being used..

$_SESSION['variablename'] = ''; // Use that to define a variable in a session

Then I would use..

if(isset($_SESSION['variablename'])) {
if($_SESSION['variablename'] != "") {
header('Location: login.php');
} else {
echo "Session is blank";
}
}


header('Location: login.php'); // Redirect to a different page
 
ooo the fun I had last night with isset and empty!

Whatever you do in PHP make sure you use them 2 in the right places otherwise it causes murder! I was having things set but set as empty, and I had an if statement that checked isset instead of empty :@ so it returned true everytime!
 
Back
Top Bottom