Re: Cookies

From: Date: Thu, 11 Jan 2001 23:11:29 +0000
Subject: Re: Cookies
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-34137@lists.php.net to get a copy of this message
http://php.net/setcookie Not sure why you want to put them in a cookie, though. The browser is going to keep representing the $HTTP_AUTH_USER and password variables as long as they don't quit their browser... ----- Original Message ----- From: "David Smith" <webmaster@indywebdesign.com> Newsgroups: php.general Sent: Thursday, January 11, 2001 3:14 AM Subject: [PHP] Cookies > > > How cn I make the following code set a cookie for vars username and > password?? > > <?php > > $auth = false; // Assume user is not authenticated > > if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) > > > // Connect to MySQL > > mysql_connect( 'localhost', 'root', '*****' ) > or die ( 'Unable to connect to server.' ); > > // Select database on MySQL server > > mysql_select_db( 'cfsforums' ) > or die ( 'Unable to select database.' ); > > // Formulate the query > > $sql = "SELECT * FROM user WHERE > username = '$PHP_AUTH_USER' AND > password = '$PHP_AUTH_PW'"; > > // Execute the query and put results in $result > > $result = mysql_query( $sql ) > or die ( 'Unable to execute query.' ); > > // Get number of rows in $result. > > $num = mysql_numrows( $result ); > > if ( $num != 0 ) > > > // A matching row was found - the user is authenticated. > > $auth = true; > > } > > } > > if ( ! $auth ) > > > header( 'WWW-Authenticate: Basic realm="Combat Flight Center Members > Area"' ); > header( 'HTTP/1.0 401 Unauthorized' ); > echo 'Authorization Required.'; > exit; > > } else > > > echo '<!-- Login Successful -->'; > } > > ?> > > WreckRman2 > Combat Flight Center > http://www.combatfs.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#34137) next »