如何阻止我的php登录在内容区输出结果?

时间:2013-05-02 01:17:16

标签: php html forms login include

我有一个正在进行的网站,设计工作已经完成,但我正致力于使网站充满活力。我在网站上有一个部分,其中包含一个包含登录表单的登录部分。我的登录脚本有效,但是当用户登录时,登录表单会保留在网站上,成员部分会出现在我的内容所在的位置。以下是网站设计/配置的示例:

的index.php --file包括设计exp:include(标题,导航,内容,侧栏,页脚)

的部分
<body>
<?php include("header.php");?>
<?php include("navigation.php");?>
<?php include("content.php");?>
<?php include("sidebar.php");?>
<?php include("footer.php");?>
</body>

Content.php - 包含php include和导航片段以输出链接index.php?od=file

<?php
if ($_REQUEST["od"]=="home") include("incs/news.html");
elseif ($_REQUEST["od"]=="portfolio") include("incs/portfolio.html");
elseif ($_REQUEST["od"]=="tutorials") include("incs/tutorials.html");
elseif ($_REQUEST["od"]=="resources") include("incs/resources.html");
elseif ($_REQUEST["od"]=="services") include("incs/services.php");
elseif ($_REQUEST["od"]=="contact") include("incs/contactus.html");
elseif ($_REQUEST["od"]=="webhosting") include("incs/webhosting.html");
elseif ($_REQUEST["od"]=="webdesign") include("incs/webdesign.html");
elseif ($_REQUEST["od"]=="webdevelopment") include("incs/webdevelopment.html");
elseif ($_REQUEST["od"]=="repairs") include("incs/repairs.html");
elseif ($_REQUEST["od"]=="login") include("login/login-exec.php");
elseif ($_REQUEST["od"]=="logfail") include("login/login-failed.php");
elseif ($_REQUEST["od"]=="register") include("login/register-form.php");
elseif ($_REQUEST["od"]=="registerex") include("login/register-exec.php");
elseif ($_REQUEST["od"]=="regsuccess") include("login/register-success.php");
elseif ($_REQUEST["od"]=="denied") include("login/access-denied.php");
elseif ($_REQUEST["od"]=="account") include("login/member-index.php");
elseif ($_REQUEST["od"]=="profile") include("login/member-profile.php");
elseif ($_REQUEST["od"]=="logout") include("login/logout.php");
else include("incs/news.html");
?>

的sidebar.php - 包含用于登录的html表单

<form id="loginForm" name="loginForm" method="post" action="login/login-exec.php">
                        <p align="left" class="description"><label for="username"><b>Username:</b></label></p>
                        <p align="left"><input name="username" type="text" id="username" size="40" maxlength="40" /></p>

                        <p align="left" class="description"><label for="password"><b>Password:</b></label></p>
                        <p align="left"><input name="password" type="password" size="40" maxlength="100" id="password" /></p>

                        <p align="right"><input name="login" type="submit" value="Log In" id="submit" /></p>

                        <h6 align="left">&raquo; <a href="./index.php?od=register"><font color="#565656">Not Registered?</font></a></h6>
                        <h6 align="left">&raquo; <a href="./index.php?od=fgtpsswd"><font color="#565656">Forgot Password?</font></a></h6>
                        <input type="hidden" name="ref" value="{REF}" />
                    </form>

/login/login-exec.php

    if($result) {
    if(mysql_num_rows($result) == 1) {
        //Login Successful
        session_regenerate_id();
        $account = mysql_fetch_assoc($result);
        $_SESSION['SESS_ACCOUNT_ID'] = $account['id'];
        $_SESSION['SESS_FIRST_NAME'] = $account['firstname'];
        $_SESSION['SESS_LAST_NAME'] = $account['lastname'];
        session_write_close();
        header("location: ../index.php?od=account");
        exit();
    }else {
        //Login failed
        header("location: /index.php?od=logfail");
        exit();
    }

登录脚本位于名为/ login /的文件夹中,我希望我的表单切换到指向安全部分的链接的成员面板。我猜一个php if和elseif语句是必要的,但不确定。有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

这应该有效。 (的sidebar.php)

<? if($_SESSION['SESS_ACCOUNT_ID'] == ''): ?>    
<form id="loginForm" name="loginForm" method="post" action="login/login-exec.php">
    <p align="left" class="description"><label for="username"><b>Username:</b></label></p>
    <p align="left"><input name="username" type="text" id="username" size="40" maxlength="40" /></p>
    <p align="left" class="description"><label for="password"><b>Password:</b></label></p>
    <p align="left"><input name="password" type="password" size="40" maxlength="100" id="password" /></p>
    <p align="right"><input name="login" type="submit" value="Log In" id="submit" /></p>
    <h6 align="left">&raquo; <a href="./index.php?od=register"><font color="#565656">Not Registered?</font></a></h6>
    <h6 align="left">&raquo; <a href="./index.php?od=fgtpsswd"><font color="#565656">Forgot Password?</font></a></h6>
    <input type="hidden" name="ref" value="{REF}" />
</form>
<? endif; ?>