Re: Cookies, Sessions and Login Proceess

From: Date: Mon, 12 Nov 2001 17:44:52 +0000
Subject: Re: Cookies, Sessions and Login Proceess
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74311@lists.php.net to get a copy of this message
On Mon, 12 Nov 2001, Joe Van Meer wrote: > Thx Christopher for replying. Ok, let me see if I understand you > correctly... > > The user enters username and password on index.php, this is posted to > login.php. On login.php after I verify the user is who he/she says they are > I set a cookie called "accessedbefore" to "yes" and redirect them to the Exactly. > main page. Am I allowed to set a cookie and redirect them after determining > who the user is? How would I redirect them after setting the cookie? Header You can set a cookie any time before any standard output is sent to the browser (and before you send a new Location header). Your login.php can look something like this (with pseudo-ish code) ... <?php $input_ok = validate_user_input( $username, $password ); if( $input_ok ){ $user_ok = authenticate_user( $username, $password ); if( $user_ok ){ setcookie( "myuser", "ok", time()+7200, "/" ); header( "Location: congratulations.html" ); } else { header( "Location: go_away.html" ); } } else { header( "Location: go_away.html" ); } ?> ~Chris /"\ \ / September 11, 2001 X We Are All New Yorkers / \ rm -rf /bin/laden

« previous php.general (#74311) next »