Web Development Information |
|
Developing A Login System With PHP And MySQL
Most interactive websites nowadays would require a user to log in into the website's system in order to provide a customized experience for the user. Once the user has logged in, the website will be able to provide a presentation that is tailored to the user's preferences. A basic login system typically contains 3 components: 1. The component that allows a user to register his preferred login id and password 2. The component that allows the system to verify and authenticate the user when he subsequently logs in 3. The component that sends the user's password to his registered email address if the user forgets his password Such a system can be easily created using PHP and MySQL. ================================================================ Component 1 - Registration Component 1 is typically implemented using a simple HTML form that contains 3 fields and 2 buttons: 1. A preferred login id field Assume that such a form is coded into a file named register.html. The following HTML code excerpt is a typical example. When the user has filled in all the fields, the register.php page is called when the user clicks on the Submit button. [form name="register" method="post" action="register.php"] [input name="login id" type="text" value="loginid" size="20"/][br] [input name="password" type="text" value="password" size="20"/][br] [input name="email" type="text" value="email" size="50"/][br] [input type="submit" name="submit" value="submit"/] [input type="reset" name="reset" value="reset"/][/form] The following code excerpt can be used as part of register.php to process the registration. It connects to the MySQL database and inserts a line of data 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 excerpt assumes that the MySQL table that is used to store the registration data is named tbl_login and contains 3 fields - the loginid, password and email fields. The values of the $loginid, $password and $email variables are passed in from the form in register.html using the post method. ================================================================ Component 2 - Verification and Authentication A registered user will want to log into the system to access the functionality provided by the website. The user will have to provide his login id and password for the system to verify and authenticate. This is typically done through a simple HTML form. This HTML form typically contains 2 fields and 2 buttons: 1. A login id field Assume that such a form is coded into a file named authenticate.html. The following HTML code excerpt is a typical example. When the user has filled in all the fields, the authenticate.php page is called when the user clicks on the Submit button. [form name="authenticate" method="post" action="authenticate.php"] [input name="login id" type="text" value="loginid" size="20"/][br] [input name="password" type="text" value="password" size="20"/][br] [input type="submit" name="submit" value="submit"/] [input type="reset" name="reset" value="reset"/][/form] The following code excerpt can be used as part of authenticate.php to process 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 to DB!");@mysql_select_db("tbl_login") or die("Cannot select 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 in the system. please try again."; exit();}else{ print "successfully logged into system."; //proceed to perform website's functionality - e.g. present information to the user} As in component 1, the code excerpt assumes that the MySQL table that is used to store the registration data is named 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 3 - Forgot Password A registered user may forget his password to log into the website's system. In this case, the user will need to supply his loginid for the system to retrieve his password and send the password to the user's registered email address. This is typically done through a simple HTML form. This HTML form typically contains 1 field and 2 buttons: 1. A login id field Assume that such a form is coded into a file named forgot.html. The following HTML code excerpt is a typical example. When the user has filled in all the fields, the forgot.php page is called when the user clicks on the Submit button. [form name="forgot" method="post" action="forgot.php"] [input name="login id" type="text" value="loginid" size="20"/][br] [input type="submit" name="submit" value="submit"/] [input type="reset" name="reset" value="reset"/][/form] The following code excerpt can be used as part of forgot.php to process 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 to 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()==0){ print "no such login in the system. please try 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 component 1, the code excerpt assumes that the MySQL table that is used to store the registration data is named tbl_login and contains 3 fields - the loginid, password and email fields. The value of the $loginid variable is passed from the form in forgot.html using the post method. ================================================================ Conclusion The above example is to illustrate how a very basic login system can be implemented. The example can be enhanced to include password encryption and additional functionality - e.g. to allow users to edit their login information. Used with the author's permission.
MORE RESOURCES: Web Performance Optimization (WPO) Solution Market Set for Exceptional Growth from 2024 to 2032 openPR Where to sell a website? SitePoint Best laptops for programming of 2025 TechRadar Web Design and Development Muskegon Community College StackBlitz achieves $4M ARR in 4 weeks for their AI web development platform with Claude - Anthropic Front End Developer Skills and Responsibilities Simplilearn Rediscover the Joy of Early Web Development With XSLT The New Stack The looming disaster of AI SitePoint 23 In-Demand Full Stack Developer Skills in 2025 Simplilearn Northeastern grad goes from schooling to working full time at web development startup he created Northeastern University How Much does Website Development Cost in 2022? Appinventiv The Rock It! Co. earns Gold Award in Web Development The Post and Courier Best web design software of 2024 TechRadar How do I fix this? SitePoint Latest News: Rising Senior Uses Computer Science Coursework to Thrive in Web Development Role Muhlenberg College From accounting to web development: Meet this Ironhack grad making big strides in programming Refresh Miami Best Website Development Tools for 2024 DesignRush Best PHP Frameworks for Web Development in 2024 Simplilearn 【react roulette】 Português Agência Brasília Best web development tool of 2025 TechRadar Top 10 Front End Languages: A Beginner's Guide Simplilearn CSS5 Features for Faster Web Design Analytics Insight Top Web Design Trends for 2025 Designmodo Top Web Design Trends in 2024 Netguru New Web Development Tool Pulls Design Tokens From Figma The New Stack HTML6 and CSS5: What’s New for Web Developers? Analytics Insight The birth of the Web CERN 11 Applications and Uses of Python in 2025 Simplilearn Best website design service of 2025 TechRadar 38 Web Development Stats You Should Know in 2024 Influencer Marketing Hub Web of Science Research Assistant Clarivate PhyloJS: Bridging phylogenetics and web development with a JavaScript utility library Wiley Online Library 25 Examples Of About Us Pages For Inspiration Search Engine Journal 18 stunning parallax scrolling websites Creative Bloq Best Web Development Bootcamp (2024): Udemy Complete Python Pro Bootcamp Review by Compare Before Buying Business Wire 【react roulette】 Português Agência Brasília 35 Best Web Design Companies 2024 Built In Digital marketing firm inks merger deal with local company The Business Journals How to Use ChatGPT to Build a Website Themeisle |
RELATED ARTICLES
Three Things Every Website Should Do When I started my company in 2002, I knew I needed to have a website. Why? To provide credibility! How can a company be "real" in this day and age if it doesn't have a website? So, like many companies, I published an informational website that explained "here's who we are, and here's what we do". Effectively Using Robots Meta Tags The "robots" meta tag, when used properly, will tell the search engine spiders whether or not to index and follow a particular page. For the purposes of this article, we will be using the "( )" symbols to represent the "" in html coding. CSS - Maximum Benefits What is CSS?CSS is a simple file which controls the visual appearance of a Web page without compromising its structure. Using CSS we can control our font size, font color, link color and many other attributes on our web page. 17 Tips to Plan a Website Everyone wants one.Everyone wishes they knew how to make one. Product Promoting: Getting The Response When you publish a content site there are times when affiliate products are not the only products you want to recommend.Situations when you'll find you'll want to promote a non-affiliate businesses' product(s). Improve Web Sales Figures Forever And Ever Amen! "How do I improve web site sales figures?" The CEO roared at the web developer. The web developer looked at his boss a little confused and mumbled something about it not being his core competence with him being a programmer and all. CPanel Fantastico - Features and Benefits Fantastico is a 3rd-party cPanel add-on and can be purchased and added to the standard cPanel interface. Fantastico allows you to quickly install a variety of open-source scripts. Planning A Usable Website: A Three-step Guide A website is like an information flow, with you as the provider and your site visitors as the receivers of the information. If you don't plan your website with this in mind right from the start, you could find yourself with a brand new website that solves all your immediate needs. Direct Sales and Your Corporate Website - A Creative Marketing Plan that Works! Creatively marketing your corporate site takes time in the set up but you will learn that building your customers isn't about marketing your products but getting your name and reputation into the minds of internet customers.I have randomly chosen Watkins to design a marketing approach but you will see how to apply this concept to any direct sales company. 3 Ways To Increase Your Websites Conversion rate Everywhere you look these days, people are telling you that in order to sell through your website, you need tons of traffic.Well, even though my business is traffic generation, *I'm* going to tell you that it's a BIG FAT LIE!The secret of a successful website isn't just in the amount of visitors it has; it's in the amount of visitors that are converted to buyers. Web Accessibility: The Basics What is web accessibility & why is it important?Web accessibility is about making your website accessible to all Internet users (both disabled and non-disabled), regardless of what browsing technology they're using. In addition to complying with the law, an accessible website can reap huge benefits on to your website and your business. Website Success is Key The popular search engine Google indexes over 8 billion websites. Is one of them yours, or is your website just floating around in cyberspace and you're hoping your customers will just find you? Is your website a benefit to your organization or company? Is it just an expensive showpiece or is it of true value?These are some of the many questions that can be asked when launching a new website. Do Dancers Need A Website? Dance is how you pamper your soul and satiate your creativity. Mesmerized and overwhelmed with the pleasure that the dancer relishes while dancing, often there are some practical aspects that tend to get overlooked. Up The Sandbox! Go to any internet marketing forum you want these days andone of the topics is sure to be whether or not there is a"sandbox" at Google where new sites are forced to come andplay for 3-6 months before joining the ranks of ranked andsearched results. On the surface it would appear that thisis so. Developing A Login System With PHP And MySQL Most interactive websites nowadays would require a user to log in into the website's system in order to provide a customized experience for the user. Once the user has logged in, the website will be able to provide a presentation that is tailored to the user's preferences. Web Success Secret - Keep Your Visitors Interested Visitors to your site come looking for information or solutions to their problems. They will remain there if they find what they are looking for. Topics to Add When Creating an Alternate and Modern Medicine Web Directory Alternate medicine finds its own place in the hearts and minds worldwide and has a separate following to back its existence. There are many subcategories that could be added to the modern and alternate medicine website directories. Trust Us! Sending Credible Messages A company must earn and keep trust or sales don't happen. Imagine that last Sunday, while you were reading the paper, you saw an ad for a great deal on a digital camera. Give Your Business a Cash Infusion Whether you have your own business already, or are looking for a way to cash in on the profit potential of reaching millions of internet users - you can't afford NOT to read this??.. 7 Reasons YOU Need a Website 1) A marketing necessityI still hear it said from time to time that you really do not need a website if you are a private practice professional. I disagree. |
home | site map |
© 2006 |