qmqmqm Posted March 5, 2009 Share Posted March 5, 2009 Hi I have the following code copied almost directly copied from http://pear.php.net/manual/en/package.authentication.auth.intro.php except for the specified table in the db. However this is not working for me. The text that logged-in user can see is never shown, although I entered the username/password as appeared in the table. Does anyone know why this is? Thanks, Tom <?php /* * import the authentication class of PEAR */ require_once ('../../../php/PEAR/Auth.php'); function show_login_form() { echo '<form method="post" action="login.php"> <p>Username <input type="text" name="username" /></p> <p>Password <input type="password" name="password" /></p> <input type="submit" value="Login" /> </form><br /> '; } $db_username = "root"; $db_password = ""; $db_host = "localhost"; $db_database = "my_db"; // All options: // Use specific username and password columns. // Retrieve all fields. $options = array( 'dsn' => 'mysql://$db_username:$db_password@$db_host/$db_database', 'table' => 'users', 'usernamecol' => 'user_name', 'passwordcol' => 'passwd' ); // Create the Auth object: $auth = new Auth('DB', $options, 'show_login_form'); // Add a new user: $auth->addUser('me', 'mypass'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Restricted Page</title> </head> <body> <?php // Start the authorization: $auth->start(); // Confirm authorization: if ($auth->checkAuth()) { // Print the user's name: echo "<p>You, {$auth->getAuthData('first_name')} {$auth->getAuthData('last_name')}, are logged in and can read this. How cool is that?</p>"; } else { // Unauthorized. echo '<p>You must be logged in to access this page.</p>'; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/148157-pear-auth-class-problem/ Share on other sites More sharing options...
jjacquay712 Posted March 6, 2009 Share Posted March 6, 2009 I dont know what your problem is but this is how i would approach creating a log in form: <?php mysql_connect("Ur Stuff"); if ( $_POST['username'] && $_POST['password'] ) { $rows = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='{$_POST['username']}' AND password='{$_POST['password']}''")); if ($rows > 0) { echo 'Logged in'; } else { echo 'Wrong username or pass'; } } else { //echo form } ?> Link to comment https://forums.phpfreaks.com/topic/148157-pear-auth-class-problem/#findComment-777782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.