Posted on Sunday 12th October 2008 at 09:37 PM
Hey guys new to php and this website (its great BTW) i have just started to get the PHP-user system up on my site and was wondering wheather there is a protected page script so when a member is loged in they can see the page but when they are not logged in they cant. They may already one one up i found the one where it protects the page for admins and i changed it to allow members to view it aswell but i put it on the page i want to protect and if im not logged in i can still view it, but up the top of the page it says sorry u cant view this page lol. its this script....
<?php
include('config.php'); // gets the database and sitename if needed
session_start(); // starts session
if($logged[username]){
$checkuser = $logged['username']; // gets the username for the code below
$user = mysql_query("SELECT userlevel FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchuser = mysql_fetch_assoc($user);
$admin = $fetchuser['userlevel']; // will get the userlevel from the sql database
if($admin == 6) {
echo "Zup, admin? Your userlevel is $admin"; // displays admin message (userlevel 6)
}
if($admin == 4) {
echo "Zup Mod? Your Userlevel is $admin"; // displays mod message (userlevel 4)
}
if($admin == 2) {
echo "Sorry, members do not have access to this page."; // displays normal user message (userlevel 2)
}
} else {
echo "You are not logged in, login, then come back to this page."; // no account logged in
}
?>
Where do i place it to protect me page?
Any help would be great beware i am a noob lol if u have not already noticed
Cheers
<?php
include('config.php'); // gets the database and sitename if needed
session_start(); // starts session
if($logged[username]){
$checkuser = $logged['username']; // gets the username for the code below
$user = mysql_query("SELECT userlevel FROM members WHERE username = '$checkuser' ORDER BY id DESC LIMIT 1") or die (mysql_error());
$fetchuser = mysql_fetch_assoc($user);
$admin = $fetchuser['userlevel']; // will get the userlevel from the sql database
if($admin == 6) {
echo "Zup, admin? Your userlevel is $admin"; // displays admin message (userlevel 6)
}
if($admin == 4) {
echo "Zup Mod? Your Userlevel is $admin"; // displays mod message (userlevel 4)
}
if($admin == 2) {
echo "Sorry, members do not have access to this page."; // displays normal user message (userlevel 2)
}
} else {
echo "You are not logged in, login, then come back to this page."; // no account logged in
}
?>
Where do i place it to protect me page?
Any help would be great beware i am a noob lol if u have not already noticed
Cheers