Member authentication with PHP and MySQL

From: Date: Sun, 12 Aug 2001 23:47:24 +0000
Subject: Member authentication with PHP and MySQL
Groups: php.db 
Request: Send a blank email to php-db+get-11277@lists.php.net to get a copy of this message
Hi! I'm trying to authenticate members by using php and MySQL. This is what I've come to so far: <?php $auth = false; // Assume user is not authenticated if (isset( $email ) && isset($password)) { // Connect to MySQL mysql_connect( 'localhost', 'Xephiroth', 'lordoftherings' ) or die ( 'Unable to connect to server.' ); // Select database on MySQL server mysql_select_db( 'members' ) or die ( 'Unable to select database.' ); // Formulate the query $sql = "SELECT * FROM memberinfo WHERE email = '$email' AND password = '$password'"; // 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="Members only"' ); header( 'HTTP/1.0 401 Unauthorized' ); echo 'Authorization Required to enter the member area'; exit; } else { echo ' -SITE CONTENT- '; } ?> How do I make the authentication to go to site: members.php?charnick=$charnick Where $charnick is brung from the DB line who was authenticated? So that Peter won't end up at John 's membersite? Thanks for your time and expertese! Best regards Cato

« previous php.db (#11277) next »