将用户重定向到登录页面 [英] redirect users to the login page

查看:280
本文介绍了将用户重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下登录脚本..

I've got the following login script..

<?php
$name = $_POST["name"];
$password = $_POST["password"];
$query = "SELECT * FROM users WHERE username = '$name'
         AND password = '$password'";
$q=mysql_query($query) or die(mysql_error());
$result = mysql_query($query);
if (mysql_fetch_row($result)) {
  /* access granted */
  session_start();
  header("Cache-control: private");
  $_SESSION["access"] = "granted";
  header("Location: ./menu.php");
  } else
  /* access denied &#8211; redirect back to login */
  header("Location: ./login.html");
  ?>
  mysql_close();
  ?>

但我现在需要菜单重定向到登录页面没有登录用户谁?以prevent直接访问?

But what would I now need to "menu" to redirect users who are not logged in to the login page? to prevent direct access?

感谢。

推荐答案

在menu.php?

session_start();
if (!isset($_SESSION['access']) || $_SESSION['access'] != "granted") {
  header("Location: ./login.html");
  exit();
}

这篇关于将用户重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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