Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/12050-mysql-login/
Share on other sites

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:
[code]if(!isset($_SESSION['userid'])) {
die("No access to this page");
}

[/code]

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:
[code]
header('location: login.php');
[/code]
Sends them to the login page.
Link to comment
https://forums.phpfreaks.com/topic/12050-mysql-login/#findComment-45819
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/12050-mysql-login/#findComment-45877
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.