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: Best web design software of 2024 TechRadar My Sublime Text Setup in 2024 for Web Development Laravel News 9 Chicago Web Design and Development Agencies To Know Built In Chicago Why (and How) I Learned Web Development as a Data Scientist Towards Data Science The future of web development AWS Blog Best web development tool of 2024 TechRadar This Web Development Grad is Developing for Esports Full Sail News From Data Scientist to AI Developer: Lessons Building an Generative AI Web App in 2023 Towards Data Science How Much does Website Development Cost in 2024? Appinventiv PHP[TEK] 2024: Pioneering the Future of Web Development in Chicago Security Boulevard Angular 18 will arrive next week InfoWorld Wakulla Correctional Institute inmates learn web development, life skills through coding program WCTV Charlotte ad agency AC&M Group acquires Argentina web development company Axlot The Business Journals 11 of the Best Web Development Agencies in New York + Tips on How to Choose the Best Agency Influencer Marketing Hub Launch Code recruiting applicants for its free web development course KTVI Fox 2 St. Louis Top 32 Web Development Agencies For All Things Technical Influencer Marketing Hub Web Developer: Best Low-Stress, High-Pay Job in America? Dice Insights 15 Highest Paying Countries for Web Developers Yahoo Finance Freddy Vasquez: Web Development and Small Business Marketing Reading Magazine Best PHP Frameworks for Web Development in 2024 Simplilearn Can AI-Powered Tools End the Web Developer Shortage? Spiceworks News and Insights How to Use Node Js for Backend Web Development Simplilearn 38 Web Development Stats You Should Know in 2024 Influencer Marketing Hub Website Design | Alton | Edwardsville | St Louis RiverBender.com 15 Web Design and Development Trends You Need To Know in 2024 SpaceCoastDaily.com Leaked: New Web Development Tools from Google AI Business Top 16 eCommerce Web Development Companies To Grow Your Sales Influencer Marketing Hub 9 Simple Projects to Learn Front-End Web Development Yonkers Times Watch this web developer dismantle vintage computers Technical.ly Netlify Announces Software Developer Kit (SDK) to Accelerate Modern Web Development for Enterprises PR Newswire Top 10 eCommerce Web Design Trends to Keep You Relevant in 2024 Influencer Marketing Hub The Web Coding Boot Camp Harper College News Web Design Companies & Agencies In Austin To Know Built In Austin Computer Information Technology - Applications Development Southeast Community College News Are you up to build the next best website? Get started with one of these 5 web design courses Fortune 6 ways AI is changing web design Creative Bloq |
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 |