PHP ajax login form using Jquery
Because a lot of responses to the previous post php ajax tutorial create ajax based login form using jquery, and asking about some bug fixxing incl IE bugs, i decide to create a new PHP ajax login functionality using Jquery, and here it is…
- Completely recoded
- Tested in IE6, FF3, Opera9 and i think should be worked in other modern browsers as well
- Easliy switch the data source between database and PHP array
- Login authentication can be using username or email, or even both of ‘em by changing the config
- Redirect target (on success) can be changed in config file
- Message and Text controled by array variable which could be changed in 1 file
- Jquery 1.2.3, never tested with the prior version
- PHP5, If you running prior version then you need to make some changes, probably but not limited at class constructor to make it compatible with your PHP version.
- Switch the data source : Turn the value of USEDB constant in login.config.php into true, and modify the db_config array values as needed, to use array vars turn it false and modify the user_config array values
- change the authentication method : change the LOGIN_METHOD constant value, possible values:
- user : match the username and password
- email : match the user email and password
- both : match the username or user email and password
- switch automattic redirection : turn the value of autoRedir var in login.js to true
- change the redirect target : change the value of SUCCESS_URL constant in login.config.php, for example you need to automatically redirect to user profile, so change it into “index.php?profile=”.$_SESSION['exp_user']['username']
- change error message and text : change the array values accordingly at login.lang.php
- Thanks to John resig and the jquery developer team, thanks guys you made my life easier
- Please do not link to the download file directly, link to this page instead
- This script is absolutely free, credits nor link is not required but will be great if this site got ‘em
Demo & Download
- The demo available here use admin|admin@localhost|123456 as the test account
- Download the source again please do not link to the file directly, link to this page instead.
CREATE TABLE `tbl_user` ( `userid` integer (11) NOT NULL AUTO_INCREMENT , `username` varchar (50) NOT NULL, `useremail` varchar (100) NOT NULL, `userpassword` varchar (50) NOT NULL, PRIMARY KEY (`userid`) ) TYPE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci; BEGIN; INSERT INTO `tbl_user` (`userid`, `username`, `useremail`, `userpassword`) VALUES(1, 'admin', 'firstname.lastname@example.org', 'e10adc3949ba59abbe56e057f20f883e'); INSERT INTO `tbl_user` (`userid`, `username`, `useremail`, `userpassword`) VALUES(2, 'user', 'email@example.com', 'e10adc3949ba59abbe56e057f20f883e'); COMMIT;
The Jquery file can be downloded at jquery.com If you found something doesnt work as expected just let me know.
Bug in google chrome beta which reported by Azo has fixed, the problem is caused by 2 byte chunk data in ajax JSON response which makes the response not valid JSON format, those chunks produced by files which include (required) in login.post.php (“login.lang.php” & “login.class.php”).
Now worked in IE6+, FF 2+, Opera 9+, Safari 3+ (for windows), Google Chrome beta