我只是想对我现在的网站的一个目录下的html文件做一个保护,如果用户没登录,就无法访问,跳转到登陆页面。
大家有好的idea吗?越简单越好,俺是业余的,太高深的不会做目录里的html可以修改,但是不能改成动态的.php,那样就不连贯了。因为这些页面早已生成。
大家有好的idea吗?越简单越好,俺是业余的,太高深的不会做目录里的html可以修改,但是不能改成动态的.php,那样就不连贯了。因为这些页面早已生成。
调试欢乐多
你输入地址,无法访问,自动跳转到登陆
login.php
<?php
//session_start();
if (isset($_POST['user']) && isset($_POST['password'])) {
if($_POST['user'] == '123' && $_POST['password'] == '123') { setcookie('isLogin', 'true');
}else {
setcookie('isLogin', 'false');
}
}
?>
<form action="" method="POST">
UserName:<input type="text" name="user" value="" /><br/>
Password:<input type="password" name="password" value=""><br/>
<input type="submit" value="submit" name="submit" />
</form>
<html>
<head>
<script>
function $(id){
return document.getElementById(id);
}
function openOrNot() { var a_all_cookies = document.cookie.split(';');
var loginCookie = a_all_cookies[0].split('=');
if (loginCookie[1] == 'false')
window.location.href = "../index.php";
}
</script>
</head>
<body onload="openOrNot()">
fdasfdsf
fdsaf
asfdasfsd
</body>
</html>
AllowOverride AuthConfig2、生成密码文件用htpasswd在/etc/apache目录下生成一个passwords密码文件并创建一个test用户
htpasswd -c /etc/apache/passwords test按照提示输入两遍密码然后修改密码文件的权限chown root.nobody /etc/apache/passwords chmod 640 /etc/apache/passwords 在/var/www/htdocs/ftp目录下生成一个。htaccess文件,内容如下AuthType Basic AuthName “By Invitation Only”
AuthUserFile /etc/apache/passwords Require valid-user4、重启apache
/etc/rc.d/rc.httpd restart现在你再次访问http://localhost/ftp的时候,就会提示你输入用户名和密码了。
注意:用htpasswd生成密码文件的时候,只要第一次用-c这个参数以后添加用户,不要使用-c这个参数。
<?php
if(!defined('KEY'))define('KEY', true);
?>然后在每个不想让浏览器直接输入链接访问的页面中加入
<?php
if (! defined ( 'KEY' ))
exit ();
?>