doutang1946 2015-11-08 18:56
浏览 80
已采纳

登录Apache后如何将凭据传递给PHP脚本

I'm trying to set up a php script which needs to get credentials that user has passed on login form. I have already set up form authentication on my apache server with login form which redirects user to php script but when I access "session" cookie I get a long encrypted line rather than separate records for username and password. Is there a way to make apache to pass these values to php script? And if there is, how I can access those values?

Please see details below:

.htaccess for directory where php script is - webi/.htaccess:

AuthFormProvider ldap
AuthType form
AuthFormLoginRequiredLocation "http://my.server.addr/webi/login/index.html"
AuthName "LDAP"
AuthLDAPURL "ldap://ldap.server.ip/ou=users,dc=example,dc=com"
Require valid-user
Session On
SessionEnv On
SessionCookieName session path=/
SessionCryptoPassphrase secret
SessionMaxAge 900

php script - webi/profile/index.php:

    <?php
        $cookie_name = "session";
        if(isset($_COOKIE[$cookie_name]))
        {
            echo "<li class='active'><a href='#'><span>$_COOKIE[$cookie_name]</span></a></li>";
            echo "<li><a href='#'><span>Update profile data</span></a></li>";
            echo "<li><a href='#'><span>Company</span></a></li>";
            echo "<li class='last'><a href='#'><span>Contact</span></a></li>";
        }
        else
        {
            echo "<li class='active'><a href='#'><span>NO PROFILE</span></a></li>";
        }
    ?>

login form - webi/login/index.html:

<form class="form" method="POST" action="login-handler">
        <input type="text" name="httpd_username" value="" placeholder="Username">
        <input type="password" name="httpd_password" value="" placeholder="Password">
        <button type="submit" name="login" id="login-button">Login</button>
        <input type="hidden" name="httpd_location" value="http://my.server.addr/webi/profile" />
</form>

.htaccess for directory where login form is - webi/login/htaccess:

Require all granted

.htaccess for login-handler directory - webi/login/login-handler/.htaccess

SetHandler form-login-handler
AuthFormProvider ldap
AuthType form
AuthFormLoginRequiredLocation "http://my.server.addr/webi/login/index.html"
AuthName "LDAP"
AuthLDAPURL "ldap://ldap.server.ip/ou=users,dc=example,dc=com"
Require valid-user
Session On
SessionEnv On
SessionCookieName session path=/
SessionCryptoPassphrase secret
SessionMaxAge 900

Thanks)

  • 写回答

1条回答 默认 最新

  • douweidao3882 2015-11-13 10:07
    关注

    I found a partial solution for this issue. One can use _SERVER['PHP_AUTH_USER'] to access username passed through login form authentication.

    I'm still however unable to access password.

    Thanks to this post - http://software.danielwatrous.com/access-apache-ldap-authentication-details-in-php/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来