如何配置Apache以允许在PHP中进行身份验证


How to configure Apache to allow authentication in PHP

我的登录页面不像在localhost中那样工作。我重构了PHP页面和相关脚本,但没有任何结果,直到我在搜索中偶然发现Apache PHP模块配置问题。

我已经阅读并尝试了以下建议:

  • http://php.net/manual/en/features.http-auth.php
  • 为什么未设置$_SERVER["PHP_AUTH_USER"]和$_SERVER["PHP-AUTH_PW"]
  • 是否未设置PHP_AUTH_USER

但没有一个对我有效。也许,我的问题是独一无二的。也许不是。

到目前为止,.htaccess具有:

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteRule ^index'.php$ - [L]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule . /index.php [L]
     </IfModule>
     RewriteEngine On
     RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTP_HOST} ^genieverse.com [NC]
RewriteRule ^(.*)$ http://www.my_site.com/$1 [L,R=301]

而log_in.php具有:

 //Get custom error function script
require_once('Server_Includes/scripts/common_scripts/feature_error_message.php');
if(preg_match('/Basic's+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'],      $matches))
{ list($the_name,  $the_password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($the_name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($the_password); }
//Filter incoming values
$username    =    (isset($_POST["username"])) ? trim($_POST["username"])    :     "Username";
$password = (isset($_POST["password"])) ? trim($_POST["password"])    :    "Password";

rest继续到log_in页面表单。

每次我输入用户名和密码,然后点击提交,登录页面重新加载请求相同。就像他们从来没有被发送过一样。

我到底需要做什么?

PS:Web服务器是共享主机,Apache 2.2.31,PHP 5.4.45

没关系。我已经解决了我上传了一个自定义的php.ini文件。它包括:session.auto_start=在上

但这并没有奏效。两者都没有进行任何形式的htaccess破解工作。因此,我创建了一个phpinfo.php文件,其中包含: