I want to write a script that can only be accessed by an administrator.
This is how I want to do it:
session_start();
if (!isset($_SESSION['user_id'])) { //not logged in
//redirect to homepage
header("Location: http://domain.com/index.php");
die();
}
if ($_SESSION['user_level'] != 1337) { //not admin
//redirect to homepage
header("Location: http://domain.com/index.php");
die();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //form is submitted
//validate the submitted data
//submit the query
}
//form goes here
My question is: Is there a better way of validating this (eg. should all three conditionals be nested) or is this enough?
Cheers,
n1te
die()ing anywayfunctionsas pointed out.