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

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

PHP中文网
Freigeben: 2016-05-25 17:13:46
Original
1289 Leute haben es durchsucht

.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;
    }
}
  
?>
Nach dem Login kopieren

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


Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage