0

我有一个正在进行中的网站,设计工作已经完成,但我正在努力使网站动态化。我在网站上有一个包含登录表单的登录部分。我的登录脚本正在运行,但是当用户登录时,登录表单仍保留在网站上,并且成员部分出现在我的内容所在的位置。这是网站设计/配置的示例:

Index.php --file 包含设计 exp 的部分:include(header, navigation, content, sidebar, footer)

<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 包含和导航片段,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 语句是必要的,但不确定。有人有什么想法吗?

4

1 回答 1

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; ?>
于 2013-05-02T02:35:31.520 回答