{"id":539,"date":"2022-12-19T15:55:17","date_gmt":"2022-12-19T10:25:17","guid":{"rendered":"https:\/\/qwebtechnologies.com\/blog\/?p=539"},"modified":"2024-09-08T00:18:08","modified_gmt":"2024-09-07T18:48:08","slug":"login-system-using-php-and-html","status":"publish","type":"post","link":"https:\/\/qwebtechnologies.com\/blog\/login-system-using-php-and-html\/","title":{"rendered":"Free Learn Login System Using PHP and HTML."},"content":{"rendered":"\n<p>Here is a basic example of a login system using PHP and HTML:<\/p>\n\n\n\n<p>This code first displays an HTML form that asks the user for a username and password. When the form is submitted, the PHP code runs and checks the provided username and password against a database of users. <\/p>\n\n\n\n<p>If the <a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_login_form.asp\" target=\"_blank\" rel=\"noreferrer noopener\">login<\/a> is successful, it sets a session variable to indicate that the user is logged in and redirects to the home page. If the login is unsuccessful, it displays an error message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"216\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2023\/01\/login-system-using-PHP-and-HTML.jpg\" alt=\"login system using PHP and HTML\" class=\"wp-image-787\" srcset=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2023\/01\/login-system-using-PHP-and-HTML.jpg 372w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2023\/01\/login-system-using-PHP-and-HTML-150x87.jpg 150w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><figcaption class=\"wp-element-caption\">login system using PHP and HTML<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/qwebtechnologies.com\/blog\/login-code\/\" target=\"_blank\" rel=\"noreferrer noopener\">Read more Related posts<\/a><\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#login-system-using-php-and-html-example\">login system using PHP and HTML Example:<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"login-system-using-php-and-html-example\">login system using PHP and HTML Example:<\/h2>\n\n\n\n<p><strong>HTML FORM:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\"login.php\" method=\"post\"&gt;\n  &lt;label for=\"username\"&gt;Username:&lt;\/label&gt;&lt;br&gt;\n  &lt;input type=\"text\" id=\"username\" name=\"username\"&gt;&lt;br&gt;\n  &lt;label for=\"password\"&gt;Password:&lt;\/label&gt;&lt;br&gt;\n  &lt;input type=\"password\" id=\"password\" name=\"password\"&gt;&lt;br&gt;&lt;br&gt;\n  &lt;input type=\"submit\" value=\"Submit\"&gt;\n&lt;\/form&gt; \n<\/code><\/pre>\n\n\n\n<p><strong>PHP FILE:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ Check if the form was submitted\nif ($_SERVER&#91;'REQUEST_METHOD'] == 'POST') {\n  \/\/ Get the username and password from the form\n  $username = $_POST&#91;'username'];\n  $password = $_POST&#91;'password'];\n\n  \/\/ Connect to the database\n  $conn = new mysqli('localhost', 'dbuser', 'dbpass', 'dbname');\n  if ($conn-&gt;connect_error) {\n    die(\"Connection failed: \" . $conn-&gt;connect_error);\n  }\n\n  \/\/ Check if the username and password are correct\n  $result = $conn-&gt;query(\"SELECT * FROM users WHERE username='$username' AND password='$password'\");\n  if ($result-&gt;num_rows &gt; 0) {\n    \/\/ Set a session variable to indicate that the user is logged in\n    $_SESSION&#91;'logged_in'] = true;\n    \/\/ Redirect to the home page\n    header('Location: index.php');\n    exit;\n  } else {\n    \/\/ Display an error message\n    echo 'Invalid username or password';\n  }\n}\n?&gt;\n<\/code><\/pre>\n\n\n\n<p>This is just a basic example and you may want to consider adding additional security measures such as hashing the passwords, using prepared statements to prevent SQL injection attacks, and implementing rate limiting to prevent brute force attacks.<\/p>\n\n\n\n<p><strong>Read More.<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list is-grid columns-3 wp-block-latest-posts\"><li><div class=\"wp-block-latest-posts__featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"128\" height=\"72\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/Java-Frameworks.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"Java Frameworks\" style=\"\" srcset=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/Java-Frameworks.jpg 1280w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/Java-Frameworks-768x432.jpg 768w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/Java-Frameworks-150x84.jpg 150w\" sizes=\"auto, (max-width: 128px) 100vw, 128px\" \/><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/qwebtechnologies.com\/blog\/java-frameworks\/\">The Ultimate Guide to the Top 10 Java Frameworks for 2024.<\/a><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"128\" height=\"72\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/javascript-location-reload-true.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"javascript:location.reload(true)\" style=\"\" srcset=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/javascript-location-reload-true.jpg 1280w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/javascript-location-reload-true-768x432.jpg 768w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/javascript-location-reload-true-150x84.jpg 150w\" sizes=\"auto, (max-width: 128px) 100vw, 128px\" \/><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/qwebtechnologies.com\/blog\/javascript-location-reload-true\/\">A Comprehensive Guide to Using javascript:location.reload(true) in Web Development<\/a><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"128\" height=\"72\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/php-explode-multiple-separators.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"php explode multiple separators\" style=\"\" srcset=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/php-explode-multiple-separators.jpg 1280w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/php-explode-multiple-separators-768x432.jpg 768w, https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/10\/php-explode-multiple-separators-150x84.jpg 150w\" sizes=\"auto, (max-width: 128px) 100vw, 128px\" \/><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/qwebtechnologies.com\/blog\/php-explode-multiple-separators\/\">PHP explode Multiple Separators: A Comprehensive Guide.<\/a><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"96\" height=\"96\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/09\/Copy-Constructor-in-Java-e1727713503548.webp\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"Copy Constructor in Java\" style=\"\" \/><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/qwebtechnologies.com\/blog\/copy-constructor-in-java\/\">Copy Constructor in Java: A Complete Guide<\/a><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"96\" height=\"96\" src=\"https:\/\/qwebtechnologies.com\/blog\/wp-content\/uploads\/2024\/09\/php-project-topics-e1727713601441.webp\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"PHP Project Topics\" style=\"\" \/><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/qwebtechnologies.com\/blog\/php-project-topics\/\">50 Ultimate PHP Project Topics to Elevate Your Development Skills.<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Here is a basic example of a login system using PHP and HTML: This code first displays an HTML form that asks the user for a username and password. When the form is submitted, the PHP code runs and checks the provided username and password against a database of users. If the login is successful, &#8230; <a title=\"Free Learn Login System Using PHP and HTML.\" class=\"read-more\" href=\"https:\/\/qwebtechnologies.com\/blog\/login-system-using-php-and-html\/\" aria-label=\"Read more about Free Learn Login System Using PHP and HTML.\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":787,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-539","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-login-code"],"_links":{"self":[{"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":6,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions\/1116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/media\/787"}],"wp:attachment":[{"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qwebtechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}