PHP file redirecting user when it is not supposed to
<p>I'm making a login script for a Server CP although it doesn't seem to work as intended, I can login but if I go to the index page it doesn't redirect me to the admin page, code here:</p>

<p>All Code: <a href="http://pastebin.com/DC8fVtD5" rel="nofollow">http://pastebin.com/DC8fVtD5</a></p>

<p>Could anyone shed any light on this for me please? :) The problem is with the cookies or the sessions but I'm not sure how to fix it. The script needs to check user input against a mysql database and see if they have an account for the website and if so, log them in. It seems to be logging me in although admin.php seems to be redirecting me to index.php when $logged != 0. I haven't been able to find a fix for it and it is driving me nuts. D:</p>
