您如何阻止人们进入应该用作登录页面的页面? [英] How do you stop people from going to a page that should be used as log in page?

查看:84
本文介绍了您如何阻止人们进入应该用作登录页面的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php新手.我正在尝试允许用户登录网站.步骤如下:php脚本检查$ _POST ['submit']是否设置,如果设置了$ _POST ['submit'],则检查用户输入是否与数据库中的数据匹配,如果输入正确,则将用户重定向到登录页面.我试图阻止用户访问输入正确的php脚本重定向他们的页面,但是我做不到.我已经尝试过empty和isset函数,但是它们不起作用. Facebook如何设法让用户登录而不将其重定向到其他页面.当您登录Facebook时,URL为 http://facebook.com .谢谢您的回答

I am new to php. I am trying to allow users to log in a website. Here are the steps: the php script checks if the $_POST['submit'] is set, if it is set it check if the user input match data in the database, if inputs are correct it redirects users to a log in page. I am trying to stop users from accessing the page that the php script redirect them when their input are correct but I can't. I already try the empty and the isset function but they don't work. How does facebook manage to have users log in without redirecting them to other pages. When you log in facebook the url is http://facebook.com. Thank you for your answers

推荐答案

成功登录后:

$_SESSION['logged_in'] = true;

每个页面的顶部:

session_start();
if (!$_SESSION['logged_in'])
{
    header('Location: login.php');
    die();
}

登录页面顶部:

session_start();
if ($_SESSION['logged_in'])
{
    header('Location: other_page_here.php');
    die();
}

有关会话的更多信息,请此处.

More on sessions here.

这篇关于您如何阻止人们进入应该用作登录页面的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆