validating user session in php
<p>I am creating few pages (including login page) which should only be accessible by a sysadmin. </p>

<p>In login.php after the user's credentials have been verified. I set a session variable like so:</p>

<pre><code>mysql_connect("localhost", $values['uname'], $values['password']) or 
die(mysql_error());
echo "Connected to MySQL&lt;br /&gt;";
mysql_select_db("somedb") or die (mysql_error());

session_start();
$_SESSION['level'] = 'admin';
header('Location: /admin/index.php');
</code></pre>

<p>And then in the index.php page I am doing the following:</p>

<pre><code>&lt;?php 
if($_SESSION['level'] !== 'admin'){
    header("location:../admin/login.php");
}
?&gt;
</code></pre>

<p>But it does not seem to work.  Everytime I am being redirected to login.php  (even after successfully logging in via login.php).<br />
Is there something wrong with this approach and how I am going about this?</p>

<p>Basically on page other than login.php I need a way to make sure user is logged in...</p>
