Home > php教程 > PHP源码 > PHP 生成 .htpasswd 文件的用户名和密码

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

PHP中文网
Release: 2016-05-25 17:13:46
Original
1223 people have browsed it

.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></p>\n";
    }
  
    if ($password == &#39;&#39; || preg_match(&#39;/\s/m&#39;, $password)) {
        $error .= "<p><strong>Invalid Password.</strong></p>\n";
    }
  
    if ($error == &#39;&#39;) {
        echo "<p>Success</p>\n";
        echo "<h1>" . htmlspecialchars($username) . ":" . crypt($password) . "</h1>\n";
    } else {
        echo $error;
    }
}
  
?>
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template