我正在尝试创建一个简单的登录系统,没有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。
干杯 路易斯
答案 0 :(得分:1)
我猜测以下if语句是代码的“成功”分支。
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,虽然不是一个显示阻止,但通常不赞成。这就是简单/易用的框架。即使你不使用它们,你也应该花一些时间阅读它们,因为它们做了很多事情,你会在一周内学到更多,而不是一辈子的摸索通过它。继续......继续回到你多年前写过的代码总是很有趣,并且想一想,“伙计,我曾经很糟糕!”。
实施例。
<?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>';
}
}
答案 1 :(得分:0)
当验证用户时,您可以使用php header()函数。
标题('位置:http://www.example.com/'。$ _ SESSION ['username']。'。php');
答案 2 :(得分:0)
我认为您不希望每个用户都有单独的文件。通常我会做的是,一旦用户被证明被授权您将其重定向到授权页面,然后该页面将呈现您的Web应用程序的应用程序数据。
此页面对每个人来说基本相同,您可以使用与该用户关联的数据填充它。我告诉你,你有links
表和meetings
表,它会将user_id
与会议/链接相关联。您可以使用模板引擎或在PHP中滚动自己的模板引擎。根据您的应用程序开始获取的深度,您可能希望查看模板引擎以呈现HTML。