hi all

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
leesands
Forum Newbie
Posts: 2
Joined: Sat Mar 28, 2009 10:57 am

hi all

Post 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
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: hi all

Post 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();
}
?>
Post Reply