February 10, 2004

First real (sort of) PHP/mySQL code

Someone at DSL Reports asked about a PHP / mySQL solution for having someone login and then gain access to other pages. If not logged in, they wouldn't gain access. The DSLR thread is here.

I played a (very little) bit with mySQL but I'm very comfortable with SQL. Created a basic User/Password/Name table to contain the logon info. Found some sample code at a couple of sites with Managing Users with PHP Sessions and MySQL being a terrific reference. The actual hardest part was (remember this is my 1st PHP page) getting the session variables working properly in PHP to store the fact that someone had successfully logged in and also their name to display on a second page. I found all the info I needed at a tutorial on sessions.

To see the page, go to the login page at http://www.levinecentral.com/php/logon.php where you can enter userid: test password:abc123. You will be redirected to http://www.levinecentral.com/php/logged_in.php where you can logoff. After clicking logoff, you are returned to the logon page. Going directly to http://www.levinecentral.com/php/logged_in.php you will see that you can't get to it since you're not logged on and it redirects you back to the logon page.

If you want the source code, just ask.

Edit: Well many people have asked, so if you want the source code, you can download it from http://www.levinecentral.com/php/PHP_Login.zip

Posted by David on February 10, 2004 8:18 PM
Comments

I would like the code as well. Thank you.

Posted by: Jack at February 1, 2005 2:30 PM

I like the sample above, could you please send me the source code.

Thanks

Sylvain

Posted by: Sylvain at October 7, 2004 10:09 PM

I am starting to learn php and mysql on my own. I like the sample login-logoff script. Kindly send me the source. It will be a big help.

Thanks

Posted by: kurt at August 29, 2004 10:03 AM

I like the sample above, could you please send me the source code. It's been a couple of weeks I have been looking for a simple login & logoff script in php/mysql.
Thanks,
Seenu

Posted by: Seenu at April 28, 2004 1:42 PM

I like the sample above, could you please send me the source code. It's so hard to find a simple PHP login/logoff script.

Posted by: Jim at March 21, 2004 7:12 PM