开发者

Deny Access to specific html-document

I'm currently trying to deny access to a specific html-document which should only be accessable if you are logged in, but I have no clue how to do it.

If you manually type in the url and html document like this http://example.de/noaccessf开发者_StackOverflow社区orunregisteredusers.html its no problem to access the page, but I don't want that.

I really hope someone can help me with this. As I really have no clue what to look for.


What programming language are you using for membership management?

You could use something like PHP and embedded a script into your HTML page, to quite easily check to see if someone has logged in. You could use a PHP session to store the state of the user, then on every page check to see whether the session is valid.

At login:

<?php
session_start(); 
$_SESSION['username'] = 'joeblogs';
$_SESSION['memberrole']   = 'member';
$_SESSION['time']     = time();
?>

Then in the pages you want to restrict put something like this at the top:

<?php
if($_SESSION['memberrole'] != 'member'){
header ("Location: http://example.com/sorry.html"); 
}
?>

Please be aware that there are a lot of security issues with the code above, so if you do use this approach, do some research into SESSION security, hashing etc. Also note that the .html page would then become a .php page instead.

Or you could always restrict access to the page using .htaccess file in your websites root folder. If you're using CPanel you can login and usually they have an option to restrict pages, which require a username and password to view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜