AI编程助手
AI免费问答

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

PHP中文网   2016-05-25 17:13   1482浏览 原创

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

<?php   
// - - - - - - - - - - - - - - - - - - -
// Author: Christopher Hair
// Website: www.chrishair.co.uk
// - - - - - - - - - - - - - - - - - - -
  
if (isset($_POST[&#39;submit&#39;])){
  $error = &#39;&#39;;
  $username = trim(stripslashes($_POST[&#39;username&#39;]));
  $password = trim(stripslashes($_POST[&#39;password&#39;]));
  
    if ($username == &#39;&#39; || preg_match(&#39;/\s/m&#39;, $username)) {
        $error .= "<p><strong>Invalid Username.</strong>\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;
    }
}
  
?>

 以上就是PHP 生成 .htpasswd 文件的用户名和密码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

php免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。