使用 PHP 进行基本身份验证:
登录:
<?php session_start();$_SESSION=array();session_destroy(); ?>
<form method="POST" action="yoursite.php">
Username: <input name="username"><br>
Password: <input name="password" type="password"><br>
<button type="submit">Submit</button>
</form>
您的网站:
<?php
session_start();
if(isset($_POST['username'])) {
$username = trim($_POST['username']);
$userpw = trim($_POST['password']);
//here you have to check if the credentials are correct
$user_may_see_content = false;
//
if(user_may_see_content) {
$_SESSION['mayHaveRequest']=1;
//now go to page
} else {
header("Location: <link_to_loginsite>");exit();
}
}
//if user may see page
if(isset($_SESSION['mayHaveRequest']) && $_SESSION['mayHaveRequest']==1): ?>
$_SESSION['mayHaveRequest']=0;
?>
<!-- SECRET HTML CODE FOR AUTHENTICATED USERS -->
<?php else:
header("Location: <link_to_loginsite>");exit();
endif;
?>
这只是给你一个例子。
希望有帮助。