Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基本php密码保护_Php_Apache_Password Protection - Fatal编程技术网

基本php密码保护

基本php密码保护,php,apache,password-protection,Php,Apache,Password Protection,我现在拥有的是一个apache服务器,它保存着一些包含图片和家庭视频的文件夹。我已经转发了端口,并让它在我输入ip时显示文件夹。我唯一的问题是,任何人都可以从世界各地访问它。我在网上找到了这段php代码,因此我可以对这些文件进行密码保护: <?php // Define your username and password $username = "someuser"; $password = "somepassword"; if ($_POST['txtUsername']

我现在拥有的是一个apache服务器,它保存着一些包含图片和家庭视频的文件夹。我已经转发了端口,并让它在我输入ip时显示文件夹。我唯一的问题是,任何人都可以从世界各地访问它。我在网上找到了这段php代码,因此我可以对这些文件进行密码保护:

<?php 

// Define your username and password 
$username = "someuser"; 
$password = "somepassword"; 

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { 

?> 

<h1>Login</h1> 

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <p><label for="txtUsername">Username:</label> 
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> 

    <p><label for="txtpassword">Password:</label> 
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p> 

    <p><input type="submit" name="Submit" value="Login" /></p> 

</form> 

<?php 

} 
else { 

?> 

<p>This is the protected page. Your private content goes here.</p> 

<?php 

} 

?> 

登录
努力学习并实施它

您可以通过创建htpasswd文件。只需输入用户名和密码,就会生成htpasswd文件的条目。您可以使用创建一个htaccess文件,该文件将对您的站点或目录进行密码保护。此htpasswd生成器创建使用MD5算法散列的密码,这意味着您可以将其用于任何平台(包括Windows和Linux)上托管的站点。您还可以在自己的服务器上使用PHP创建htpasswd密码——但这种技术仅适用于Linux。阅读有关htpasswd文件的更多信息


从这里了解更多信息。

也许您最好在apache服务器中指定密码。在谷歌上搜索
.htaccess文件
。使用适当的CHMODS和.htaccess htaccess deny/allo非常感谢您的帮助。我现在了解了htaccess和htpasswd。我现在有了一些可靠的身份验证!