dtz88967 2013-12-05 20:17
浏览 23
已采纳

限制访问php页面直到用户登录[关闭]

Hi im trying to write a script that restricts the access of user to a page until he has logged in with username and password. I keep getting undefined index file for username and password? any one have any suggestions??

<!DOCTYPE html>
<html lang="en">
<head>
<title> Exercise 3</title>
<meta charset="utf-8">
</head>
<body>
<?php
    $name = “Frank”;
    $age = “28”;
    var_dump($name);
    echo "<br>";
    print_r($name);
    echo "<br>";
    var_dump($age);
    echo "<br>";
?>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • douhei8633 2013-12-05 20:31
    关注

    Rather a big topic. The easiest way to protect a directory is to have the web server do the grunt work and setup an htaccess file. http://www.htaccesstools.com/htaccess-authentication/ is a online tool to do that.

    To do it through PHP you need to get the user login and then give a session cookie to tell the other URLS if he is logged in. If the cookie is hackable or the other urls assume he is logged in then he can easily bypass your login. Unless it is only a single page you want to secure.

    If you want to store users in a database there are a number of security issues that appear quickly. The user input must be completely cleaned of any charactors that may allow for hacks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算