龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP 生成 .htpasswd 文件的用户名和密码

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
p.htpasswd 主要是 apache 使用的基于文件的用户名和密码的存储/p

.htpasswd 主要是 apache 使用的基于文件的用户名和密码的存储


<?php
 
// - - - - - - - - - - - - - - - - - - -
// Author: Christopher Hair
// Website: www.chrishair.co.uk
// - - - - - - - - - - - - - - - - - - -
 
if (isset($_POST['submit'])){
  $error = '';
  $username = trim(stripslashes($_POST['username']));
  $password = trim(stripslashes($_POST['password']));
 
	if ($username == '' || preg_match('/\s/m', $username)) {
		$error .= "<p><strong>Invalid Username.</strong></p>\n";
	}
 
	if ($password == '' || preg_match('/\s/m', $password)) {
		$error .= "<p><strong>Invalid Password.</strong></p>\n";
	}
 
	if ($error == '') {
		echo "<p>Success</p>\n";
		echo "<h1>" . htmlspecialchars($username) . ":" . crypt($password) . "</h1>\n";
	} else {
		echo $error;
	}
}
 
?>
精彩图集

赞助商链接