Security on each page

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
chrchcol
Forum Newbie
Posts: 15
Joined: Fri Jul 14, 2006 5:35 am

Security on each page

Post by chrchcol »

I have a login and validation page before someone can get into a simple web application I am writing.

Is there anything that I can include on each script page that requires them to have logged in before accessing it?

Does anyone have the best idea?

Chris
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

You can include a script.

Code: Select all

include('checkLogin.php');
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

Wouldn't it be better to be a require() in this case? With include(), it will give an error and then continue but with require() it will halt all execution... right?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

PapiSolo wrote:Wouldn't it be better to be a require() in this case? With include(), it will give an error and then continue but with require() it will halt all execution... right?
yea that's right. I RARELY use include.
griffinmt
Forum Commoner
Posts: 35
Joined: Sun Jul 16, 2006 8:37 pm
Location: Michigan

Post by griffinmt »

More to the point, after a successfull login, set a SESSION variable to indicate who has just logged on.

then, as suggested, include a php file that has in it (among other things):

Code: Select all

<?PHP
session_start();
.
.
if (!isset($_SESSION['userid']))
{
// not logged in so go handle
}
else
{
// user is logged in so do the other stuff
}
?>
Post Reply