rafdre Posted June 15, 2006 Share Posted June 15, 2006 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 BasicAuthMySQLHost localhostAuthMySQLUser “root”AuthMySQLPassword “”AuthMySQLDB testDBAuthMySQLUserTable user_infoAuthMySQLNameField user_nameAuthMySQLPasswordField user_passwdAuthMySQLPwEncryption noneAuthMySQLEnable Onrequire valid-userThis 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 RequiredThis 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.regardsRafal Quote Link to comment https://forums.phpfreaks.com/topic/12050-mysql-login/ Share on other sites More sharing options...
Chips Posted June 15, 2006 Share Posted June 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12050-mysql-login/#findComment-45819 Share on other sites More sharing options...
rafdre Posted June 15, 2006 Author Share Posted June 15, 2006 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 .htaccessThank you in advance for helpregardsRafal Quote Link to comment https://forums.phpfreaks.com/topic/12050-mysql-login/#findComment-45877 Share on other sites More sharing options...
rafdre Posted June 20, 2006 Author Share Posted June 20, 2006 I have found solution.Problem was here:AuthMySQLUser “root”AuthMySQLPassword “”I have created user rafal with password rafal and changed these lines to:AuthMySQLUser rafalAuthMySQLPassword rafaland it works fineregards Rafal Quote Link to comment https://forums.phpfreaks.com/topic/12050-mysql-login/#findComment-47782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.