where are you registering this session variable? if you register it at the top of the page, this will never work.
but, more importantly is
if (session_is_registered ( "username" ) )
which basically does nothing.
also you set $query = "ok" and then check to see if $query != ok (without the quotes)
to get the desired effect, change this to
if (session_is_registered("username"))
{
header("Location: /warning.php");
}
p.