I've been following this guide (http://www.tutorialspoint.com/php/php_mysql_login.htm) to build a custom Php & MySQL Login System, but I can't get mine to work.
The login can fail, it checks against the database, it authenticates the user is true or false, but it doesn't redirect the user once it is completed. It just takes them back to the login page, and displays no HTML, Php or CSS elements.
I've attached both the core Login.php & Session.php
Login.php:
include("databaseconfig.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT * FROM pacientes WHERE nombre = '$myusername' and apellidos = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1)
{
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: http://www.google.com/");
}
else {
$error = "Your Login Name or Password didn't work!";
}
}
Session.php
include('databaseconfig.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"SELECT nombre FROM pacientes WHERE nombre = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['nombre'];
if(!isset($_SESSION['login_user'])){
header('location: www.google.co.uk');
}
I'm not sure why it's not redirecting to a new page. It won't even redirect to Google. As I said;
The connection to the database works, The code does check against the database, The code does not send the user to the next page.
The purpose of this system is that users will log in, and be able to see their own profile. But I can't get the system to redirect to any page at the moment.
I appreciate your support, and hope you can help.