I have tried login and it didn't work, when I login, it just stay at the blank page. No errors has shown.
I have made a form in index.php. If the user hasn't logout, the name of user will output on the page. And if the user hasn't login, it will show a login form. The following code below:
<div class="topRight">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include "config/dbconnect.php";
if(isset($_SESSION['login'])&&!empty($_SESSION['login'])) {
$name = $_SESSION['user_info']['name'];
echo '<p> <a href="profileUser"> Profile : $name </a>';
} else {
echo '<form action="actions/login.php" method="POST">
<input type="text" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="LOGIN">
</form>';
echo '<p> <a href="registerForm.php" class="underline"> Not a member? Register here! </a> </p>
<p> <a href="actions/logout.php"> Logout </a> </p>';
}
?>
</div>
After login, it will directly to login.php as shown as below:
<?php
ob_start();
session_start();
ini_set('display_errors', 1);
error_reporting(-1);
?>
<?php
include "../config/dbconnect.php";
if(isset($_POST['submit'])) {
$username = trim($_POST['email']);
$password = trim($_POST['password']);
$username = $mysqli->real_escape_string($username);
$password = $mysqli->real_escape_string($password);
$salt = sha1(md5($password));
$epwd = md5($password.$salt);
$loginUser = " SELECT * FROM memberTable
WHERE email = '$email' AND password = '$epwd'";
$loginSuccess = mysqli_query($mysqli, $loginUser) or die(mysqli_error($mysqli));
$loginRow = mysqli_num_rows($loginSuccess);
if($loginRow === 1) {
session_start();
$_SESSION['login'] = true;
$user_info = mysqli_fetch_assoc($loginSuccess);
$_SESSION['user_info'] = $user_info; // put user_info to call all details for later use
header ("Location: ../index.php");
} else {
header ("Location: ../header.php");
}
mysqli_close($mysqli);
}
?>
The following code for dbconnect.php is below:
<?php
//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost','root','root','database_name');
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
?>
The result is when I sign in with a form, it successfully navigate to login.php. But it just stopped there with a blank page and not redirecting to index.php. There are no error has shown.
What I have done is:
- I simply put
ini_set('display_errors',1);
and it still not showing any errors.
- I have checked dbconnect.php, and the connections between index.php and login.php to dbconnect.php is linking very well.
Still it didn't show any sign like this screenshot. Am I missing something?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…