techkid
Members
-
Joined
-
Last visited
Reputation Activity
-
techkid reacted to Alluziion in Wrapping my head around sessions and cookies1. Start your sessions before HTML output so you really before the HTML tag.
2. A conditional statement to check whether a user is logged in or has admin privileges with one argument and if not, the second argument would redirect them; you can also use session_destroy();.
And as Jay said, you can do this in a single PHP file and include it where necessary.
I'm not expert myself but it's something that I've been trying to understand myself lately.
-
techkid reacted to Jay Gilford in Wrapping my head around sessions and cookies1. You need to start a session on EVERY page you want to use a session. Without doing so the session data can't be accessed
2. You will need to validate on each page that the user can access the page (ie has a valid session login) before executing code
Using the approach you have, the easiest thing would be to create a new php file - we'll call it bootstrap.php for arguments sake. Now in there you put the session start code and some code to validate the current user session is valid, and if not redirecting to the login page. Then on every page you would add an include to bootstrap.php
The one exception to this would be the login page which you would add the session start to on its own (otherwise you'll end up in an infinite loop)