Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 690
0 Users 5 Guests Online
Forum Index » PHP + MySQL » [REQ] Protected page
Posted on Sunday 12th October 2008 at 09:37 PM
ferdinor
templates/default/images/noavatar.png's Avatar
Newbie
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
Posted on Thursday 16th October 200 at 11:04 PM
schorsch
templates/default/images/noavatar.png's Avatar
Active Member
exactly the same times I had also asked and had also received answering! But unfortunately, is the contributory disappeared and I do not remember how the code was!
Posted on Monday 20th October 2008 at 08:25 PM
schorsch
templates/default/images/noavatar.png's Avatar
Active Member
can someone please the post code again? would be very grateful about it!
Posted on Monday 20th October 2008 at 08:46 PM
schorsch
templates/default/images/noavatar.png's Avatar
Active Member
sorry for my 3 posts in a row but I've found the old code and I want him here for others to provide!


it protects the site for user whose rank is at least level 2

<?php
session_start();
require("config.php");
if($logged[userlevel] < 2){
die;
}
?>
Posted on Thursday 23rd October 200 at 08:20 PM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
Why not just do:
PHP Code
1
2
3
4
5
6
7
8
9
10
<?php
if($logged['userlevel'] == 6){
//admin
}elseif($logged['userlevel'] == 4){
//mod
}else{
//user or other
}
?>
Posted on Wednesday 29th October 20 at 01:28 PM
schorsch
templates/default/images/noavatar.png's Avatar
Active Member
with the code
<?php
session_start();
require("config.php");
if($logged[userlevel] < 2){
die;
}
?>


about all you can use html and need not always echo can be used freely on the site without using html then echo ( "<a herf=\"\test.php\"> test </ a>);

backslash to use and so forth