当密码有效时,根据其用户名将用户重定向到页面



我正在尝试创建一个简单的登录系统,而无需mysql,以便我的客户可以登录,并将其定向到一个页面,该页面将显示出显示任何链接到文件的信息,并且任何会议。

我得到了:

    //If the user is validated and every thing is alright, then grant the user access to the secured account page 
                //otherwise, display error message to the user
            if ($vpb_error == '')
            {
                if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
                {
                    echo '<font style="font-size:0px;">completed</font>';
                }
                else
                {
                    echo '<div class="info">Sorry, it seems your information are incorrect and as a result, we are unable to create the required sessions to log you into your account. Please enter your valid account information to proceed. Thanks.</div>';
                }
            }
            else
            {
                echo $vpb_error;
            }
            fclose($vpb_databases);
        }
    }
    else
    {
        echo '<div class="info">Sorry, we could not get your valid username and password to process your login. Please try again or contact this website admin to report this error message if the problem persist. Thanks.</div>';
    }
}
//*********************************************************The login process ends here**********************************************************

我如何做到这一点,以便如果一切正常,它将根据它们的用户名将它们重定向到页面,即如果他们的用户名是詹姆斯,他们将被发送给james.php。

欢呼刘易斯

我猜想以下语句是代码的'成功'分支。

https://stackoverflow.com/a/768472/296555

<?php
if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
{
    header('Location: '.$_SESSION['validusername'] . '.php');
}

编辑

您应该真正考虑清理代码;这很混乱,看起来过于复杂。您正在混合HTML和PHP,尽管不是表演阻止者,但通常会皱眉。这是简单/易于使用的框架来的地方。即使您不使用它们,也应该花一些时间阅读它们,因为它们做的事情做得很好,一周之内您会学到更多的东西,而不是一生的摸索通过它。继续前进...回到您几年前写的代码,然后思考:"伙计,我曾经很烂!"总是很有趣的。

ex。

<?php
// This looks like no error but then...
if ($vpb_error == '')
{
    if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
    {
        // Mixing HTML directly in a script file
        echo '<font style="font-size:0px;">completed</font>';
    }
    // there is an error here.
    else
    {
        echo '<div class="info">Sorry, it seems your information are incorrect and as a result, we are unable to create the required sessions to log you into your account. Please enter your valid account information to proceed. Thanks.</div>';
    }
}

验证用户时,您可以使用php header((函数。

标头('位置:http://www.example.com/'.jsession ['username']。'。php'(;

我认为您不需要每个用户的单独文件。通常,我要做的是事实证明您将其重定向到授权页面,然后将其渲染为您的Web应用程序。

此页面对于每个人来说都是相同的,您可以将其与与该用户关联的数据一起使用。我是要有一个links表和一个meetings表,该表将user_id与会议/链接相关联。您可以使用模板引擎或在PHP中滚动。取决于您的应用程序如何开始获得深度,您可能想朝模板引擎呈现HTML。

相关内容

最新更新