Re: Nead Help With A Php Script

From: Date: Sat, 30 Mar 2002 19:25:07 +0000
Subject: Re: Nead Help With A Php Script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-90800@lists.php.net to get a copy of this message
> 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; }

« previous php.general (#90800) next »