会话保护 [英] session protection
问题描述
我正在一点一点地创建一个网页,测试部分网页创意.我想学习如何会话保护页面.我已经对页面进行了密码保护,但是任何人都可以通过输入 url 来访问该页面.我想会话保护我的页面,所以没有人可以这样做.我有三个页面:index.html,它具有发送password.php的表单,password.php,它使用if statments"确保密码和用户名正确(这里是if statment")
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>';
};
,以及登录后的页面 youhere.php.
, and the youhere.php which is the page once you logged in.
推荐答案
PHP 网站上有大量关于 Sessions 的信息.http://www.php.net/manual/en/intro.session.php
There is a plethora of information on Sessions on the PHP website. http://www.php.net/manual/en/intro.session.php
这是一个存储和终止会话变量的示例.http://www.php.net/manual/en/session.examples.basic.php
Here's an example with storing and killing session variables. http://www.php.net/manual/en/session.examples.basic.php
设置会话变量:
<?php
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
?>
终止会话变量:
<?php
session_start();
unset($_SESSION['count']);
?>
这篇关于会话保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!