我创建了一个登录页面,登录后会重定向到home.php页面。 使用会议。
但问题是在登录后重定向到index.php页面。
但它应该重定向到home.php
的header.php
<?php
session_start();
$valid = $_SESSION['valid'];
if(!$valid || $valid ==""){
header("Location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Management System</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="wrapperMain">
的index.php
<?php
session_start();
if(isset($_SESSION['valid'])){
header("Location:home.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Doctor's BD</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<!--Header Area Start-->
<div class="header-custom navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle navbar-tg" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="header-logo">
<a href="index.php"><img src="img/logo.png" alt="" class="img-responsive logo"></a>
</div>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<form class="login-form-style navbar-form navbar-right" role="search" action="login.php" id="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div class="form-group">
<input type="email" class="form-control" name="d_email" placeholder="Email address">
</div>
<div class="form-group">
<input type="password" class="form-control" name="d_pass" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Sign In</button>
<br>
</form>
</div>
</div>
</div>
<!--Header Area End-->
<?php include 'content.php';?>
<?php include 'footer.php';?>
home.php
<?php include 'header.php';
?>
<?php
if($_SESSION['valid']=='admin@gmail.com')
{
include 'ahome.php';
}
else
{
include 'dhome.php';
}
?>
<?php include 'footer.php';?>
login.php
<!--Login Verification Area Start-->
<?php
include 'config.php';
$d_email=$_POST['d_email'];
$d_pass=$_POST['d_pass'];
$m_d_pass=md5($d_pass);
$result= mysql_query("select * from doctor_reg where d_email='$d_email' and d_pass='$m_d_pass'",$connection) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if(is_array($row) && !empty($row))
{
$validuser = $row['d_email'];
$_SESSION['valid'] = $validuser;
}
else{
header('Refresh: 5; url=index.php');
echo "<strong style='color: #3c763d;text-align:center;'><h3>Access denied!</h3>";
echo "<h4>The user id or password you entered is incorrect</h4></strong>";
}
?>
<?php
if(isset($_SESSION['valid']))
{
header("Location: home.php");
}
?>
<!--Login Verification Area End-->
<!---->
<!---->
答案 0 :(得分:2)
首先,将所有会话检入单个文件header.php
,并将此文件包含在所有文件中。
在header.php
中,修改以下代码:
<?php
session_start();
$valid = $_SESSION['valid'];
if(!$valid || $valid ==""){
header("Location:index.php");
}
else {
header("Location: home.php");
}
?>