Trying Use Following Code Log Website Login Works Okay Session Saved Across Pages However Q34188365

I am trying to use the following code to log in to a website.The login works okay, and the session is saved across pages,however whenever a login is successful, index.php isdownloaded by the browser

How can this be fixed? If any more information is needed, pleasesay what else is needed and I will update the question.

<?phpini_set(“session.save_path”, “/home/unn_w16011531/sessionData”);session_start();// Store Session Dataecho'<!doctype HTML><head> <link rel=”stylesheet” type=”text/css” href=”style.css”> <meta charset=”UTF-8″ /> <title>Home Page</title> </head><body> <header><h2> NMC </h2></header> <nav> <!– The navigation area of the website. Contains 4 hyperlinked buttons–> <nav> <a href=”index.php” ><button class=”button”>Home</button></a> <a href=”editRecord.php” > <button class=”button”>Admin</button></a> <a href=”orderRecordsForm.php”> <button class=”button”> Select Records</button></a> <a href=”credits.php” > <button class=”button”>Credits</button></a> </nav> </nav>’;$username = filter_has_var(INPUT_POST, ‘username’) ? $_POST[‘username’]: null;$username = trim($username);$password = filter_has_var(INPUT_POST, ‘password’) ? $_POST[‘password’]: null;$password = trim($password);$page = filter_has_var(INPUT_POST, ‘page’) ? $_POST[‘page’] : null;if (empty($username) || empty($password)){ echo “You must provide a username and password”;}else{ try{ unset($_SESSION[‘username’]); unset($_SESSION[‘logged-in’]); try{ require_once(“database_conn.php”); $dbConn = getConnection(); } catch(Exception $e){ throw new Exception(“connection error: ” . $e->getMessage(), 0, $e); } $querySQL = “SELECT passwordHash from nmc_users WHERE nmc_users.username = :username”; $stmt = $dbConn->prepare($querySQL); $stmt->execute(array(‘:username’ => $username)); $user = $stmt->fetchObject(); //if a record is returned by the statement if($user){ if(password_verify($password, $user->passwordHash)){ $_SESSION[‘logged-in’] = true; $_SESSION[‘username’] = $username; if($page == 1) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/index.php’); } else if($page == 2) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/editRecord’); } else if($page == 3) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/credits.php’); } } } else{ echo ‘<p>username or password was incorrect. please try again.</p>n’; if($page == 1) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/index.php’); } else if($page == 2) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/editRecord’); } else if($page == 3) { header(‘Location:http://unn-16011531.newnumyspace.co.uk/index.php’); } } } catch(Exception $e){ echo “Record not found: ” . $e.getMessage(); }}echo'</body></html>’;?>

"We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help"
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.