普通网友 2012-03-14 02:49
浏览 49
已采纳

PHP:fopen检查客户端是否已使用受密码保护的文件进行身份验证(htpasswd)

Say I have a directory protected using htpasswd called /secret

A valid user logs into /secret.

They are redirected back to a public area.

From within that public area, is there a way within PHP to know whether the current user has authenticated with htpasswd?

Thanks for your time!

  • 写回答

1条回答 默认 最新

  • duanpang1987 2012-03-14 02:52
    关注

    Inside the /secret folder, you could have the index page set a session and check that from the public area.

    For example, in PHP:

    /secret/index.php

    <?php
    session_start();
    $_SESSION['htpasswdAuth'] = true;
    header("Location: /public/area");
    ?>
    

    Then your other scripts can do something like:

    <?php
    session_start();
    
    if(isset($_SESSION['htpasswdAuth']) && $_SESSION['htpasswdAuth'] == true)
    {
        echo 'hello authenticated user!';
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答