Jump to content


Photo

mySQL login


  • Please log in to reply
3 replies to this topic

#1 rafdre

rafdre
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 June 2006 - 07:00 AM

Hello,
I want to write some PHP scripts for my page, where I want to have some areas only for registered members, but I have some problems.


I have configured my .htaccess file like this:

AuthName "MySQL Testing"
AuthType Basic
AuthMySQLHost localhost
AuthMySQLUser “root”
AuthMySQLPassword “”
AuthMySQLDB testDB
AuthMySQLUserTable user_info
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLPwEncryption none
AuthMySQLEnable On
require valid-user

This file is in my protected folder. If I try to read HTML file stored there, I see logon window named "MySQL Testing". Everything seems to be ok, but it isn’t. I have put correct user name and password and system does not allow me to read the file. I see following message:

Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Why is that? What could be wrong here? For sure not .htaccess. Why browser could not recognize information I have entered?

Next question: Could somebody send me mall example, how to have another Login Box using PHP script? I want to have something like login.php . if user tries to read a document from protected directory, he should see login page written in php.

regards
Rafal



#2 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 15 June 2006 - 07:32 AM

For a login system, I used a method of checking the username/password against the database. If it matches up, then i set them a session with an id number.

For any page, i start with with something along the lines of:
if(!isset($_SESSION['userid'])) {
die("No access to this page");
}


Now this may not be the best idea in existance at all, indeed it may be a massive issue - I just don't know (so if anyone comments on this with knowledge, a heads up as well would be much appreciated), however, if they don't have a session set - then they see "No access to this page". Replace this with:
header('location: login.php');
Sends them to the login page.

#3 rafdre

rafdre
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 June 2006 - 12:50 PM

Thanks,

..and how about the problem with user and password?
Any idea what could be a problem here.

I have double checked in mySQL DB (testDB) and I have there user "rafal" with password "rafal", so there aren't any special characters. Encryption is not in use.
User and password was created using phpMyAdmin (insert new entry in the table user_info).
Everything seems to be correct and file .htaccess also is not wrong (there is no error message, but message: Authorization Required).

Does anybody knows how this should work (AuthMySQL)?
How the system remember users, who loged on? With cookie?

Regarding AuthMySQL. Do I have to put these information in .htaccess?:
AuthMySQLUser “root”
AuthMySQLPassword “”
This is user and password for mySQL. Maybe here is someting wrong? In the internet I have found an example without these lines in .htaccess

Thank you in advance for help

regards
Rafal



#4 rafdre

rafdre
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 June 2006 - 08:02 PM

I have found solution.

Problem was here:
AuthMySQLUser “root”
AuthMySQLPassword “”

I have created user rafal with password rafal and changed these lines to:
AuthMySQLUser rafal
AuthMySQLPassword rafal

and it works fine

regards
Rafal




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users