Page 1 of 1
need someone who helps me to get the login and database work
Posted: Sat Aug 28, 2004 2:54 am
by sean82
hallo
if someone wants to work with me on this site
crashdaygame.tk
and get the loginsystem working plz mail me or messenger
crashdaygame@hotmail.com
thanks[/url]
Posted: Sat Aug 28, 2004 9:03 am
by timvw
Here is a little sample i use to handle restricted pages
each page that is restriced shold containt at the beginning:
Code: Select all
<?php
require_once('authentication.php');
requireAdmin();
?>
Code: Select all
<?php
// authentication.php
if (!isset($_SESSION))
{
session_start();
}
function isAdmin()
{
if ($_SESSION['admin'] == 'y')
{
return true;
}
return false;
}
function requireAdmin() {
if (!isAdmin()) {
header('Location: /login.php');
exit(0);
}
}
function login($username,$password) {
if ($username == 'webmaster' && $password == 'wpass')
{
$_SESSION['admin'] = 'y';
return true;
}
else
{
unset($_SESSION['admin']);
return false;
}
}
function logout() {
$_SESSION['admin'] = 'n';
unset($_SESSION['admin']);
}
?>
Code: Select all
<?php
// login.php
require_once('authentication.php');
if (isset($_POST['login']))
{
if (login($_POST['name'], $_POST['pass']))
{
header('Location: /');
exit(0);
}
}
require_once('tpl/login.tpl'); // this is just a regular html file that contains the form
?>