SetCookie
| From: | WreckRman2 | Date: | Thu, 01 Mar 2001 21:31:20 +0000 |
| Subject: | SetCookie | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-42225@lists.php.net to get a copy of this message | ||
How can I set cookies during a login for fields in the a table? Example set
cookie for UserID which is a file in the same table. Also how would I
retrieve that info? Thanks in advance...
David Smith
<?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( 'indywebdesign' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM customers 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="Customer Support"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else
echo '<!-- Login Successful -->';
}
?>
David Smith
Indy Web Design
http://www.indywebdesign.com