TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-31-2007, 12:07 PM   #1 (permalink)
daz
The Contributor
Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
daz is on a distinguished road
Default PHP Login Class

I was going to write a tutorial, but it was too hard trying to explain OO concepts so I'm just going to release the script. Should be pretty secure. Also includes functions for validating an e-mail address and grabbing a user's IP address.

Any feedback/comments welcome, thanks.

Edit:
I updated the script to include an install file and made a few other changes. File is too big to upload here so..

http://www.csscoder.net/private/PHP Login Class v2.zip
Attached Files
File Type: zip PHP Login Class v1.zip (4.7 KB, 6760 views)

Last edited by daz : 11-13-2007 at 02:12 AM.
daz is offline  
Reply With Quote
The Following User Says Thank You to daz For This Useful Post:
codefreek (12-29-2007)
Old 10-31-2007, 05:32 PM   #2 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Great! Thanks for sharing. Such an example is great for learning OOP.
I've noticed a few things I've not seen before, like:

PHP Code:
throw new Exception(Login::ERROR_EMPTY_LOGIN); 
What's it exactly doing? And why are you doing things like that?
maZtah is offline  
Reply With Quote
The Following User Says Thank You to maZtah For This Useful Post:
alonewolf (01-26-2011)
Old 10-31-2007, 06:16 PM   #3 (permalink)
daz
The Contributor
Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
daz is on a distinguished road
Default

Hi thanks,

Exceptions are just a OO approach to error-handling. w3schools have a good tutorial on them

http://www.w3schools.com/php/php_exception.asp
daz is offline  
Reply With Quote
Old 10-31-2007, 08:23 PM   #4 (permalink)
The Wanderer
 
hostfreak's Avatar
 
Join Date: Oct 2007
Posts: 21
Thanks: 1
hostfreak is on a distinguished road
Default

Haven't had a chance to really look over much of it, but it might be beneficial to include an sql export to setup the table/field(s). I am sure you will get a lot of beginners complaining that it doesn't work, when in fact they just never set the table/field(s) up.
hostfreak is offline  
Reply With Quote
Old 11-12-2007, 05:33 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Yea, a lot of beginners will stumble and fall when it comes to that. When giving script out to the public, if the script interacts with a database then the SQL should be included. If not, your mail inbox will be filling up pretty quickly!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-13-2007, 02:13 AM   #6 (permalink)
daz
The Contributor
Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
daz is on a distinguished road
Default

Post updated! :)
daz is offline  
Reply With Quote
Old 11-13-2007, 02:28 AM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Good man, Daz :) 2MB limit for ZIP files though. Lots and lots of space!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-13-2007, 07:02 AM   #8 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Thanks for the login class Daz! A good how-to tutorial would be great.

I have an idea for you, make a simple webpage (with your css skills) with link to your login class and a full documentation on how-to use and expand the class. :)

Good linkbait. :D

Erm and Adam, I don't seem to get the PHP5 exceptions. Might want to see your inbox!
Haris is offline  
Reply With Quote
Old 11-15-2007, 01:59 PM   #9 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Exceptions article has been written for 2 days :) Just sat in proof read forum along with many other juicy articles. So many requests for Daz, don't want to make him start regretting it!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-17-2007, 01:32 PM   #10 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Exceptions article has been written for 2 days :) Just sat in proof read forum along with many other juicy articles. So many requests for Daz, don't want to make him start regretting it!
He will be getting all the popularity and monies! :p
Haris is offline  
Reply With Quote
Old 12-05-2007, 05:55 PM   #11 (permalink)
The Visitor
Newcomer 
 
Join Date: Dec 2007
Location: Florida
Posts: 2
Thanks: 0
zaxis is on a distinguished road
Default Cool

Hey this is a cool script. I'm glad I found it, I was just about to create my own Login class

For the next version I think a class that can handle more than one type of DB would be great. (I'm not sure PHP supports interfaces, but I'm sure there's a way to do it.)

Thanks,

Brian
zaxis is offline  
Reply With Quote
Old 12-05-2007, 10:39 PM   #12 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Yea, PHP can handle interfaces. It would be nice to pass in the type of the database you're wanting to use to the construct, I do admit.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-29-2007, 05:43 AM   #13 (permalink)
The Wanderer
 
deflated's Avatar
 
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
deflated is on a distinguished road
Default

Unfortunately the server is not reachable. I'm really interested in that class as I've written something similar.

Thanks in advance.

Last edited by deflated : 07-18-2010 at 01:25 PM.
deflated is offline  
Reply With Quote
The Following User Says Thank You to deflated For This Useful Post:
codefreek (12-29-2007)
Old 03-18-2009, 04:40 PM   #14 (permalink)
The Visitor
 
leeburstroghm's Avatar
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
leeburstroghm is on a distinguished road
Default

Hey all, I see there are alot of good things said about Daz login script. I am about to write/find one myself. Does this one have a session/cookie to remember the user, so they dont have to log in each time.? the initial post, has a vers 2 which is not avaialable right now. Is ver2 the one I want or will ver 1 be good. ? is ver 1 without the sql. ? any input? another script perhaps?
__________________
Eldonthian Leeburstroghm McAllister - Have a wonderful day. Its your choice!
Knowledge is the price for freedom www.1215.org
"If you make yourselves sheep, the wolves will eat you." -- Benjamin Franklin
leeburstroghm is offline  
Reply With Quote
Old 03-22-2009, 04:29 PM   #15 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

daz your link is broke.
CoryMathews is offline  
Reply With Quote
Old 03-24-2009, 06:00 PM   #16 (permalink)
The Wanderer
 
amitdgr's Avatar
 
Join Date: Mar 2009
Posts: 5
Thanks: 0
amitdgr is on a distinguished road
Default

Daz ,

The link is broken :(


Can you please upload it again ?? This will help a lot of newbies like me ....

Thanks,
Amit
amitdgr is offline  
Reply With Quote
Old 03-24-2009, 10:27 PM   #17 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Have you guys checked the date of this thread? It's more than 1 year old, surely he must have removed the file by now.
__________________
Tanax is offline  
Reply With Quote
Old 05-02-2009, 07:29 AM   #18 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Help for a Beginner.

Hi,

1st post on the site. I'm a PHP beginner well i've written a number of websites but never used OO before so was starting out and thought this login class looked pretty good. In any case I'm running PHP5, Apache2 and mySQL on Windows (my laptop) and when i try and run this seems the exception is caught and thrown out and all I ever get from the index page is:

getMessage(); } /* Include the HTML for the form */ require_once('./lib/form.php'); ?>

...as the error message. I'm hopelessly new to classes however i fully understand what the class is doing but how to debug it well i;m lost on that. I've done all the mysql set uyp work required. I know this is an old thread but any guidance even general would be much appreciated.
captainmerton is offline  
Reply With Quote
Old 05-02-2009, 01:39 PM   #19 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

try changing the start php tag from:
PHP Code:
<?
to
PHP Code:
<?php
It seems the author used php short tags (which is bad practice, in my opinion for a number of reasons) and you dont have it it enabled.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-02-2009, 03:20 PM   #20 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

sketchMedia u are a saviour. The fact that it just completely wouldnt work when it had worked for so many others made me think i was going to have to change a setting in my php.ini file or apache config but never crossed my mind about that one. Its now working. Thanks for your help.
captainmerton is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design