[REQ] Protected page

Posted on Sunday 12th October 2008 at 09:37 PM
ferdinor
ferdinor's Avatar
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 2008 at 11:04 PM
schorsch
schorsch's Avatar
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
schorsch's Avatar
can someone please the post code again? would be very grateful about it!
Posted on Monday 20th October 2008 at 08:46 PM
schorsch
schorsch's Avatar
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 2008 at 08:20 PM
ShadowMage
ShadowMage's Avatar
Why not just do:
PHP Code
  1. <?php
  2. if($logged['userlevel'] == 6){
  3. //admin
  4. }elseif($logged['userlevel'] == 4){
  5. //mod
  6. }else{
  7. //user or other
  8. }
  9. ?>
failure i sense
Posted on Wednesday 29th October 2008 at 01:28 PM
schorsch
schorsch's Avatar
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
Topic is locked