> I need a php script that checks if the there is a
> cookie set with the users username and if not it
> brings you to an other page and telling you that
> you are not loged in!


(a)  Don't cross-post all over.


(b)  Cookies 'automagically' become global variables, so
    a simple version is

    if(!isset($username)) {
        header("Location: http://www.mysite.com/login.php";);
        exit;
    }


(c)  Obviously, this won't prevent someone from
    faking a username via the querystring, so you have to
    specify that it's a cookie:

    if(!isset($_COOKIE["username"])) {
        header("Location: http://www.mysite.com/login.php";);
        exit;
    }


(d)  Doesn't work?  What do you mean, doesn't work?
    OK, if you are using pre-4.1.0, it won't work
    (you would have to look in $HTTP_COOKIE_VARS[]
    instead)  BUT note that there are known security
    flaws so you should be running 4.1.2 anyway.


(e)  It's kind of irrelevant anyway - because unless you
    are really always positively certain your users are
    cookiefied, you should be using sessions, in which case
    what you really want is

    session_start();

    if(!session_is_registered("username")) "])) {
        header("Location: http://www.mysite.com/login.php";);
        exit;
    }




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to