I am trying to set up a login system to allow a user to access a home page. When I click submit with correct login credentials, the chrome browser just shows the loading signal non-stop and does not reach the desired successful-login home page.
Here is the code for the login page - index.php:
<?php session_start(); if(isset($_POST['submit'])) { //checks if submit is clicked include_once("db.php"); //include db $username = strip_tags($_POST['email']); //get username&password $password = strip_tags($_POST['password']); //removes tags/symbols in string/sql injection // Three different sql injection prevention strategies $username = stripslashes($username); //removes slashes in sql injection $password = stripslashes($password); $username = mysqli_real_escape_string($connection, $username); $password = mysqli_real_escape_string($connection, $password); //ENCRYPTING PASSWORD - in case of db intrusion //$password = md5($password); //----------------------------------------------------------------------------- //Talk to db $sql = "SELECT * FROM users WHERE Email = '$username'"; $qry = mysqli_query($connection, $sql); $row = mysqli_fetch_array($qry); $id = $row['User_ID']; $db_password = $row['Password']; if ($password == $db_password) { $_SESSION['Email'] = $username; $_SESSION['User_ID'] = $id; header("Location: home.php"); } else { header("Location: index.php"); } } ?> JavaScript Example<div class="container">
<div class="login">
<div id="login_form">
<div class="h1Tag">
<h1>MyGarden</h1>
</div>
<div class="login_form">
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="text" name="email" id="email" placeholder="Email address"><br>
<input type="password" name="password" id="password" placeholder="Password"><br><br>
<input type="submit" name="submit" id="submit" value="Log In">
<p>Not registered?<br><a href="sign_up.php">Sign Up</a></p>
</form>
</div>
</div>
</div>
Here is the db.php page:
<?php
//$connection = new PDO('mysql:host=localhost;dbname=login_credentials;charset=utf8', 'root', '');
$connection = mysqli_connect("localhost", "root", "", "login_credentials");
if (!$connection) {
die ("Connection failed: ".mysqli_connect_error());
}
?>
Here is the home age to reach once a successful login is processed - home.php:
<?php session_start(); if(!isset($_SESSION['Email'])) { header("Location: index.php"); } ?> JavaScript Example<div class="header">
<div class="top">
<p>Share your garden with friends from around the world.</p>
<div class="logout">
<p><a href="logout.php">Logout</a></p>
</div>
</div>
<div class="bottom">
<div class="logo">
<p>MyGarden</p>
</div>
<ul class="menu">
<li><a href="">Home<a/></li>
<li><a href="">Profile<a/></li>
<li><a href="">About<a/></li>
<li><a href="">Settings<a/></li>
<li><a href="">Privacy<a/></li>
</ul>
</div>
<div class="content">
<div class="side-menu">
<ul class="features">
<li><a href="">Gardners Near Me<a/></li>
<li><a href="">Country<a/></li>
<li><a href="">Top Ratings<a/></li>
</ul>
</div>
</div>
</div>
I am using XAMPP to view the application running in Chrome on localhost and have placed all my files in the XAMPP/htdocs folder as convention.