0

好吧,我刚刚让我的登录页面正常工作,当然这导致了其他问题,我遇到的问题是,当您转到主页时,它应该允许您浏览主页并导航到其他常规页面未登录到任何类型的帐户(不必注册或登录即可查看这些页面),但由于某种原因,当我单击我的 EOI_home.php(这是我的主页)作为非登录用户它会自动将我带到我的 login.php(我的登录页面)并强制我在查看主页之前登录,这意味着我无法以未注册或非注册用户的身份查看主页我应该能够做到的登录用户。这是我的主页代码(EOI_home.php):

<head>
<title>Expression of Interest</title>
<link rel="stylesheet" href="Assign.css" type="text/css" />
</head>
<body>

<?php
require_once("nocache.php");
session_start();
if (!$_SESSION["who"]){
header("location: logoff.php");}
else {
$staff = $_SESSION["who"];
$access = $_SESSION["school_type"];
?>

<div class="title_background"><h2>Moving into Year 7 in a NSW government school in 2015</h2>
<h2>Information guide and Expression of Interest form for parents and carers</h2></div>
<p><img src="img1.jpg" width="750" height="550"></p>

<div class="right">
<?php
if ($access == S){
echo '<p><a href="process.php">Process EOI</a></p>';
echo '<p><a href="offerstatus.php">Print Offer Status Letters</a></p>';
}
if ($access == P){
echo '<p><a href="leavers.php">School Leavers</a></p>';
echo '<p><a href="comments_form.php">Add School Comments</a></p>';
}
echo '<p><a href="logoff.php">Logoff</a></p>';
}
?>
<p><a href="EOI_home.php">Home</a></p>
<p><a href="guidelines.htm">Guidelines</a></p>
<p><a href="options.htm">Your Secondary School Options</a></p>
<p><a href="eoi_form.php">Expression of Interest Form</a></p>
<p><a href="conpriv.htm">Privacy Statement and Contact Us</a></p>
<p><a href="login.php">Login</a></p>
</div>

<h1>Moving to secondary school</h1>

这是我的登录页面代码(login.php):

<body>

<?php
require_once("nocache.php");
$id = $_POST["id"];
$pword = $_POST["pword"];
$msgp = "";

if(!empty($_POST)) {
if(!empty($id) && !empty($pword)) {
    require_once("dbconn.php");
    $sql = "select username, school_type from school_info where username = '$id' and password = '$pword'";

    $rs = mysql_query($sql, $dbConn);

    if(mysql_num_rows($rs) > 0) {
        session_start();
        $_SESSION["who"] = $id;
        $_SESSION["school_type"] = mysql_result($rs, 0, "school_type");

        header("location: EOI_home.php");
    }
 } else {
    header("location: login.php");
    $msgp = '<span class="error>Incorrect username and/or password</span>';     
}
}
?>

<form method="POST" action="<?php echo $_SERVER["PHP_SELF"];?>" id="login">

ID: <input type="text" name="id" /><?php echo $msgp; ?></td><br/>
pword: <input type="password" name="pword" /><br/>

<p><a href="EOI_home.php">Home</a></p>

<input type="submit" value="log in" />&nbsp;
<input type="reset" />

</form>

这是 nochache.php 代码:

<?php
header("Cache-Control: no-cache");
header("Expires: -1");
?>

这也是 logoff.php 的代码,以防万一:

<?php
session_start();
require_once("nocache.php");
session_destroy();
header("location: login.php");
?>

顺便说一句,帐户具有不同的访问级别,并且具有不同的访问级别,主页上提供了不同的链接,例如访问级别 S 和 P。如果有人可以帮助我提供一个非常棒的解决方案,我对这些东西很陌生.

4

1 回答 1

1
<?php
    require_once("nocache.php");
    session_start();
    if ($_SESSION["who"]){
        $staff = $_SESSION["who"];
        $access = $_SESSION["school_type"];
?>

只需评论 header("location: logoff.php");

还要检查注销代码是否有效

于 2013-05-23T20:39:44.840 回答