我知道这是一个重复的问题,但我在同样的问题中尝试了所有的答案,但我仍然无法解决它。错误显示无法修改标头,当我单击登录按钮时,用户已登录但不会转到index.php页面。当我尝试将" if(isset($ _ POST [' login']))..."顶部的代码工作但javascripts不起作用。请帮帮我们..
这是代码
<!DOCTYPE html>
<?php
session_start();
?>
<html>
<head>
<title>Sign In</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<nav class="clearfix">
<ul class="clearfix">
<li><a href="index.php"><img src="img\home.png" style="margin-bottom:-2px; margin-right:3px; width:16px; height:16px;">Home</a></li>
<li><a href="speaker.php"><img src="img\speakers.png" style="margin-bottom:-1px; margin-right:4px; width:15px; height:13px;">Speakers</a></li>
<li><a href="about.php"><img src="img\about.png" style="margin-bottom:-1px; margin-right:3px; width:13px; height:12px;">About</a></li>
<li><a href="contact.php"><img src="img\contact.png" style="margin-bottom:-2px; margin-right:6px; width:13px; height:14px;">Contact</a></li>
<li><a href="reservation.php"><img src="img\reservation.png" style="margin-bottom:-2px; margin-right:5px; width:14px; height:13px;">Reservation</a></li>
<li><a href="signOut.php" id="signOut"><img src="img\signOut.png" style="margin-bottom:-2px; margin-right:6px; width:14px; height:14px;">Sign Out</a></li>
<li><a href="myAccount.php" id="user" style="text-transform:capitalize;"><img src="img\user.png" style="margin-bottom:-1px; margin-right:6px; width:13px; height:12px;"><?php echo $_SESSION['firstname']; ?></a></li>
<li><a href="signUp.php" id="signUp"><img src="img\signUp.png" style="margin-bottom:-1px; margin-right:6px; width:13px; height:11px;">Sign Up</a></li>
<li><a href="signIn.php" id="signIn"><img src="img\signIn.png" style="margin-bottom:-2px; margin-right:6px; width:14px; height:13px;">Sign In</a></li>
<li><a href="adminControl.php" id="adminControl"><img src="img\admin.png" style="margin-bottom:-3px; margin-right:6px; width:15px; height:16px;">Admin control</a></li>
</ul>
<a href="#" id="pull">Speaker Reservation</a>
</nav>
<div id="register-wrapper">
<div id="register-container">
<h2>Sign In</h2>
<p>Please provide the information below.</p>
<hr>
<div id="alert">
<span onclick="this.parentElement.style.display='none';">×</span>
Wrong Username or Password
</div>
<form id="loginform" name="loginform" method="POST">
<input name="email" class="inputbox" type="email" autofocus required="required" maxlength="30" placeholder="Email Address">
<div class="popup">
<img class="formIcons" src="img\questionMarkIcon.png" onclick="helpMessageEmail()">
<span class="popuptext" id="myPopup">The email address you used to create your account</span>
</div>
<br>
<input name="password" class="inputbox" type="password" autofocus required="required" maxlength="30" placeholder="Password">
<img class="formIcons" src="img\questionMarkIcon.png">
<br>
<input name="login" id="buttonsubmit" type="submit" value="Login">
</form>
<br>
</div>
<div id="footer">Copyright 2017</div>
<script>
$(function()
{
var pull = $('#pull');
menu = $('nav ul');
menuHeight = menu.height();
$(pull).on('click', function(e)
{
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function()
{
var w = $(window).width();
if(w > 320 && menu.is(':hidden'))
{
menu.removeAttr('style');
}
});
});
</script>
<script>
function helpMessageEmail()
{
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
</script>
<script>
function alert()
{
document.getElementById("alert").style.display = "block";
}
</script>
<script>
function ifAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "block";
}
</script>
<script>
function ifNotAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "none";
}
</script>
<script>
function ifNotLogin()
{
document.getElementById("user").style.display = "none";
document.getElementById("signOut").style.display = "none";
document.getElementById("adminControl").style.display = "none";
}
</script>
<?php
if (isset($_SESSION['signedIn']) && $_SESSION['signedIn'] == true)
//if login
{
if($_SESSION['type'] == 1)
{
echo "<script type='text/javascript'>ifAdmin();</script>";
}
elseif($_SESSION['type'] == 0)
{
echo "<script type='text/javascript'>ifNotAdmin();</script>";
}
}
//if not login
else
{
echo "<script type='text/javascript'>ifNotLogin();</script>";
}
?>
<?php
if(isset($_POST['login']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "srdatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
$sql = "SELECT id, firstname, lastname, password, emailaddress, contactnumber, type, status FROM accounts WHERE emailaddress = '$email'";
$query = mysqli_query($conn, $sql);
if($query)
{
$row = mysqli_fetch_row($query);
$id = $row[0];
$dbFirstName= $row[1];
$dbLastName= $row[2];
$dbPassword = $row[3];
$dbEmail = $row[4];
$dbContactNumber = $row[5];
$dbType = $row[6];
$dbstatus = $row[7];
}
if($email == $dbEmail && $password == $dbPassword)
{
if($dbType == 1)
{
$_SESSION['firstname'] = $dbFirstName;
$_SESSION['lastname'] = $dbLastName;
$_SESSION['email'] = $dbEmail;
$_SESSION['contactnumber'] = $dbContactNumber;
$_SESSION['signedIn'] = true;
$_SESSION['type'] = 1;
$_SESSION['status'] = $dbstatus;
header("location:index.php");
}
else
{
$_SESSION['firstname'] = $dbFirstName;
$_SESSION['lastname'] = $dbLastName;
$_SESSION['email'] = $dbEmail;
$_SESSION['contactnumber'] = $dbContactNumber;
$_SESSION['signedIn'] = true;
$_SESSION['type'] = 0;
$_SESSION['status'] = $dbstatus;
header("location:index.php");
}
}
else
{
echo "<script type='text/javascript'>alert();</script>";
}
}
?>
</body>
</html>