duancuan7057 2013-03-31 17:00
浏览 59

会话保护3 [重复]

This question is an exact duplicate of:

I am creating a webpage bit by bit, testing parts of the webpage ideas. I want to learn how to session protect a page. I have already password protected a page seccsesfully, but anybody can access the page by typing in the url. i want to session protect my page so no one can do that. i have three pages: index.html, which has the form which sends the the password.php, the password.php, which makes sure that the password and username are correct using "if statments"(here is the "if statment")

    if ($username == 'mgmb99'){
    if ($password == 'mgmb91mas'){
    header('Location: youhere.php');
    } else {
    echo 'your username or password is wrong.<a href="http://www.passwordtest.comze.com"> go back to login page </a>';
    }} else {
    echo 'your username or password is wrong.<a href="http://www.passwordtest.comze.com"> go back to login page </a>';
    };

, and the youhere.php which is the page once you logged in.

</div>
  • 写回答

2条回答 默认 最新

  • dongqian6554 2013-03-31 17:12
    关注

    there are lots of good examples online. But Session limiting (and database for that matter) are best with salt keys or hashes.

    So basically you take an id/username and a random piece of text and (for example) hash it with sha1.

    sha1($[your username].'completely random piece of text')
    

    This will give you a 40 character string which you can reproduce if you have the username and the random text. So:

    if($SESSION['id'] == sha1($[your username].'completely random piece of text')) { // now you know that the username is correct }

    Thats basically it. It does have some more tricks offcourse. But never put anything in the session that could make sence to anyone. So just use public Id's (not user ID's) in the session as well as hashed data.

    An example for a simple SESSION is here (did not check it, but its nice to start with): http://www.webdesign.org/web-programming/php/password-protect.11092.html

    Goodluck!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用