我对Sessions有疑问,并验证登录用户。
我的问题是将用户发送到“登录”页面,即。个人资料页面
if ($num_rows > 0) {
session_start();
$_SESSION['login'] = "1";
header ("Location: profile.php");
}
这是否意味着只有登录用户才能查看的任何页面必须具有php扩展名。
如果是例如profile.html,那么任何知道该文件位置的人都可以查看它吗?
那么每个个人资料页面都会有.php扩展吗?在这个php文件中,是表单和其他什么的html代码?
答案 0 :(得分:0)
您可以为每个PHP页面添加一个简短的代码,用于验证用户是否已登录,如果不是,则将用户重定向到登录页面(您还可以保存参考以将其带回他想要访问的页面)。
所以简短的回答是肯定的,你需要在每个页面中使用代码来验证用户。
答案 1 :(得分:0)
如果你想在php中编写登录系统,每个页面都需要有php扩展名,因为如果用户登录,你需要检查每一页。
如果你不想使用php,你也可以使用.htaccess文件登录系统
答案 2 :(得分:0)
为了确保维护单个入口点,可以使用htaccess来确保不能访问其他文件,并且我们将index.php文件隐藏在URL中。
The .htaccess file itself looks like this-
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
The .htaccess file will permit access to the site via urls such as
http://www.example.com/news/show
If you do not have mod_rewrite available, the entry to the site will be the same, except that the URL will contain the values needed such as:
http://www.example.com/index.php?rt=news/show
答案 3 :(得分:0)
我会说是的。如果您在每个配置文件页面中使用php脚本检查会话全局变量,那么您需要具有.php扩展名,因为它是将在您的服务器中运行的脚本。
如果你的个人资料页面没有登录保护,或者你没有使用php脚本检查会话全局变量,那么.html扩展名适用于个人资料页面。