I posted a similar post of this whith a different code, but changed it a little now, and did not get an answers that I was hoping for (the answers did not help me much). I hope this is Ok, tell me if it is not. :)
I have been trying to make a page protection for the Administrator page, and I can not get it to work. I am sure this would not have been a problem if I was not new to PHP coding, hehe.
When a normal user with the type '0' is trying to access the administrator page, index_admin.php, the user will get redirected to the normal user page, index.php. And if the user have the type '1', then the user/admin will stay on the page.
Here is the code I have been trying to get working. (This file is required in index_admin.php and it is called index_admin_check.php).
index_admin_check.php :
<?php
session_start();
?>
<?php
$vert = "localhost";
$brukarnamn = "root";
$passord = "";
$db_namn = "nettsidebunad";
$tbl_namn = "kunde_register";
// Connection to the MySQL database.
mysql_connect("$vert", "$brukarnamn", "$passord") or die ("Kan dessverre ikkje koble til databasen.");
mysql_select_db("$db_namn") or die ("Kan ikkje finna den ynkjande databasen.");
?>
<?php
if (isset($_SESSION['mittbrukarnamn'])) {
$sql1 = "SELECT `type` FROM $tbl_namn";
$rad1 = mysql_query($sql1);
$type1 = mysql_fetch_row($rad1);
if ($type1 == 0) {
echo "You do not have access to this page.";
//header("location: index.php");
} else {
echo "You have access to this page.";
}
}
?>
Some of this text is in norwegian.
$vert = $host (in english)
$brukarnamn = $usernamn (in english)
$passord = $password (in english)
$db_namn = $db_name (in english)
$tbl_namn = $tbl_name (in english)
$_SESSION['mittbrukarnamn'] = $_SESSION['myusername'] (in english)