A login system with PHP and MySQL
Posted by admin | Posted in Uncategorized | Posted on 05-02-2010
0
Many interactive websites these days need a user to log in into the website’s system to provide a customized experience for the user. Once the user has logged in, the web site will be in a position to provide a presentation that is personalised to the user’s preferences.
A basic login system usually contains three components that will be created using PHP and MySQL :
Element one: Permits registration of preferred login Id and password.
This can be created in easy HTML kind that contains three fields and a pair of buttons:
1. A most well-liked login id field
2. A most well-liked password field
3. A valid email address field
4. A Submit button
5. A Reset button
Shall we say the shape is coded into a file named register.html. The subsequent HTML code extract is a typical example. When the user has filled in all the fields and clicks on the submit button, the register.php page is called for.
[form name="register" method="post" action="register.php"]
[input name="login id" sort="text" price="loginid" size="20"/][br]
[input name="password" kind="text" value="password" size="20"/][br]
[input name="email" sort="text" value="email" size="fifty"/][br]
[input sort="submit" name="submit" price="submit"/]
[input type="reset" name="reset" price="reset"/]
[/form]
The subsequent code extract will conjointly be used as part of register.php to process the registration. The code connects to the MySQL database and inserts a line of information into the table used to store the registration information.
@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect to DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot select DB!”);
$sql=”INSERT INTO login_tbl (loginid, password and email) VALUES (“.$loginid.”,”.$password.”,”.$email.”)”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
The code extract assumes {that the} MySQL table that is used to store the registration information is named tbl_login and contains three fields – the loginid, password and email fields. The values of the $loginid, $password and $email variables are passed in from the shape in register.html using the post method.
Element two: Verification and authentication of the user.
During this the HTML form typically contains a pair of fields and a couple of buttons:
1. A login id field
2. A password field
3. A Submit button
4. A Reset button
Assume that such a form is coded into a file named authenticate.html. The following HTML code extract is a typical example. When the user has crammed in all the fields, the authenticate.php page is named when the user clicks on the Submit button.
[form name="authenticate" technique="post" action="authenticate.php"]
[input name="login id" kind="text" value="loginid" size="20"/][br]
[input name="password" type="text" worth="password" size="20"/][br]
[input kind="submit" name="submit" value="submit"/]
[input type="reset" name="reset" price="reset"/]
[/kind]
The subsequent code extract can be used as half of authenticate.php to method the login request. It connects to the MySQL database and queries the table used to store the registration information.
@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect with DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot choose DB!”);
$sql=”SELECT loginid FROM login_tbl WHERE loginid=’”.$loginid.”‘ and password=’”.$password.”‘”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print “no such login within the system. please strive again.”;
exit();
}
else{
print “successfully logged into system.”;
//proceed to perform website’s functionality – e.g. present info to the user
}
As in element one, the code excerpt assumes {that the} MySQL table that is used to store the registration information is called tbl_login and contains 3 fields – the loginid, password and email fields. The values of the $loginid and $password variables are passed in from the form in authenticate.html using the post method.
Component three: When the user forgets his logion password this third component sends his password to the users registered email address.
The HTML kind usually contains 1 field and a pair of buttons:
• A login id field
• A Submit button
• A Reset button
Assume that such a type is coded into a file named forgot.html. The following HTML code excerpt may be a typical example. When the user has crammed in all the fields, the forgot.php page is named when the user clicks on the Submit button.
[kind name="forgot" methodology="post" action="forgot.php"]
[input name="login id" sort="text" price="loginid" size="twenty"/][br]
[input type="submit" name="submit" value="submit"/]
[input type="reset" name="reset" price="reset"/]
[/kind]
The subsequent code excerpt can be used as half of forgot.php to method the login request. It connects to the MySQL database and queries the table used to store the registration information.
@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect with DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot select DB!”);
$sql=”SELECT password, email FROM login_tbl WHERE loginid=’”.$loginid.”‘”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==zero){
print “no such login in the system. please attempt again.”;
exit();
}
else {
$row=mysql_fetch_array($r);
$password=$row["password"];
$email=$row["email"];
$subject=”your password”;
$header=”from:you@yourdomain.com”;
$content=”your password is “.$password;
mail($email, $subject, $row, $header);
print “An email containing the password has been sent to you”;
}
As in element 1, the code excerpt assumes {that the} MySQL table that’s used to store the registration information is called tbl_login and contains three fields – the loginid, password and email fields. The price of the $loginid variable is passed from the shape in forgot.html using the post method.
This is often how a basic login system can be created. The software developer will embody extra tools like password encryption, access to the user profile in case they wish to edit their profile etc.
This text has been compiled by the content development team at Pegasus InfoCorp that pulls subject matter specialists from different work domains. They will be contacted through the Pegasus InfoCorp web site at information@pegasusinfocorp.com. Pegasus InfoCorp is an India primarily based internet design, internet development and on-line/offline software development company. Please visit http://www.pegasusinfocorp.com to browse more articles and know additional concerning us!
Other corporations and organizations are welcome to reprint this text on their websites provided the subsequent conditions are met.
§ The article isn’t changed in any manner
§ The article is copied as is in its entirety (as well as back links to the Pegasus InfoCorp web site).
§ The company/ organization reprinting the article agrees to defend, indemnify and hold harmless Pegasus InfoCorp, its employees, directors, officers, agents, partners and their successors and assigns from and against any and all liabilities, damages, losses, costs and expenses, as well as attorney’s fees, caused by or arising out of claims based upon the use of the article, as well as any claim of libel, defamation, violation of rights of privacy or publicity, loss of service by subscribers and infringement of intellectual property or other rights
Are you looking for the perfect tungsten wedding band, ring, or gift? Visit: tungsten rings. tungsten rings come in a variety of shapes and styles, so no matter what your preference we are sure to have the perfect ring for you. Get it now and enjoy the beauty and durability of tungsten rings!
Related Posts- Getting Started In Internet Marketing When you hear the term "internet marketing", what do you think of? For many, that term conjures thoughts of websites or spamming or search engines like Google, Yahoo and Bing. For others, it’s all about graphical design, writing fancy code or even affiliate programs. All of those answers correct, but......
- Getting Started In Internet Marketing When you hear the term "internet marketing", what do you think of? For many, that term conjures thoughts of websites or spamming or search engines like Google, Yahoo and Bing. For others, it’s all about graphical design, writing fancy code or even affiliate programs. All of those answers correct, but......
- Video Marketing – The Arguments For Making Use Of This Promotional Tool If you have been looking for a result oriented promotional technique for your online business, you should consider using video marketing. Big hikes in profits have been seen by businesses that turned to video marketing to sell their goods or services. A lot of first time marketers have also used......
- Beware Of Malware-Infected Blogs Internet users and blog-browsing addicts beware! As weblogs come back free and are quite straightforward to use, they continue to realize popularity. Hence, criminals operating on the Internet are changing into additional aware and are profiting from the utilization of those on-line personal journals to ensnare unwitting victims. Not long......
- Getting Started In Internet Marketing When you hear the term "internet marketing", what do you think of? For many, that term conjures thoughts of websites or spamming or search engines like Google, Yahoo and Bing. For others, it’s all about graphical design, writing fancy code or even affiliate programs. All of those answers correct, but......
- Inexpensive Web Hosting - Top 12 Reviews Inexpensive Web Hosting. We have compiled a detailed list of the top 12 inexpensive web hosting services with rankings based on our personal experience with each web hosting provider, visitor preference, the offered web hosting services and features of each. Web Hosting general reliability, network and server uptime, are also......
- How to Get Blog Readers Many people start blogging and just assume their blog will have readers. They don't promote much, just with a few social networking and bookmarking sites, and maybe with a few comments in forums. They just assume that if their content is interesting, people will come to their blog. Those blogs......
- Using Robo Form to Organize Your Finances For approximately three years now I have used a program called RoboForm to help me organize my finances. I have absolutely loved RoboForm and I think it could help you organize your finances (no, I don’t get a commission for saying that). If you are looking for a way......
- MonaVie Sends a Second Cease & Desist On Friday afternoon, MonaVie sent Corey Whitlaw an "official-ish" Cease and Desist Order (CDO) to my Lazy Man and Money e-mail address on the basis of his use of their trademark in my metatag keywords. I had an idea that the CDO might be coming. MonaVie had publicly tipped their......
- What Subjects Should You Cover? Choosing subjects to cover in your corporate blog is a lot like choosing the concept behind your corporate blog in the first place. When you decided to create a corporate blog, you probably had a pretty clear idea of what your main intention would be in writing for that blog.......
- First Aid, Medic Gear Personal, Field Gear Surplus Militaria Collectibles
- Belts, Belt Buckles Personal, Field Gear Surplus Militaria Collectibles
- English Print Antique Garden Nursery
- Hand Print Stepping Stones & Rocks Garden Decor Yard, Garden & Outdoor Living
- Table Sets Occasional Tables Living Room Furniture Home Store




