user level issue with redirecting
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11988317/checklogin-condition-issue-in-php">checklogin condition issue in php</a>  </p>
</blockquote>



<p>i have this quick question please, </p>

<p>i have this piece of code which isn't working properly, something about the syntax.. could you please help me with it? </p>

<p>i know it may sound stupid enough but i'm trying to understand! </p>

<p>Thanks!</p>

<pre><code>&lt;?php 
session_start();
require_once('db.php'); 
include('functions.php'); 
if (checkLogin('1 2')) {
    echo "hello ".$_SESSION['user_id']." You are now logged in."; 
} else if (checkLogin('3'))  {
echo "hey tst";
} else {}

?&gt;


function checkLogin($levels)
    {
        if(!$_SESSION['logged_in'])
        {
            $access = FALSE;
        }
        else {
            $kt = split(' ', $levels);

            $query = mysql_query('SELECT Level_access FROM users WHERE ID = "'.mysql_real_escape_string($_SESSION['user_id']).'"');
            $row = mysql_fetch_assoc($query);

            $access = FALSE;

            while(list($key,$val)=each($kt))
            {
                if($val==$row['Level_access'])
                {//if the user level matches one of the allowed levels
                    $access = TRUE;
                }
            }
        }
        if($access==FALSE)
        {
            header("Location: login.php");
        }
        else {
        //do nothing: continue
        }

    }

CREATE TABLE `users` (
  `ID` int(11) NOT NULL auto_increment,
  `Username` varchar(255) NOT NULL,
  `Password` varchar(255) NOT NULL,
  `Temp_pass` varchar(55) default NULL,
  `Temp_pass_active` tinyint(1) NOT NULL default '0',
  `Email` varchar(255) NOT NULL,
  `Active` int(11) NOT NULL default '0',
  `Level_access` int(11) NOT NULL default '2',
  `Random_key` varchar(32) default NULL,
  PRIMARY KEY  (`ID`),
  UNIQUE KEY `Username` (`Username`),
  UNIQUE KEY `Email` (`Email`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
</code></pre>
