Page 1 of 1

hi all

Posted: Sat Mar 28, 2009 11:07 am
by leesands
hi all i am makeing a website but i have got a problem i need some code that choses bewteen log in user and a non log in user. any awnser will be great thanks in advance lee

Re: hi all

Posted: Sat Mar 28, 2009 11:58 am
by crazycoders
Please move this to general coding questions, thanks...

To anwser your question, pretty simple, just use the $_SESSION array. You check if the $_SESSION array contains a value of your choice stating if the user has logged on or not. For example:

Code: Select all

CheckSession.php
<?php 
session_start();
if(!isset($_SESSION['userid'])){
heder('location: login.php');
exit();
}
?>
 

Code: Select all

login.php
Ask for user authentication in there using <form>, <input> and <submit> tags

Code: Select all

dologin.php
<?php
session_start();
/*Use the database to validate login credentials then*/
if($validlogin == true){
$_SESSION['userid'] = $userid;
header('location: firstpage.php');
exit();
}
?>