doutang3077 2015-02-09 02:45
浏览 66

安全的PHP Web服务(使用用户名和密码)

How can I set a username and password for my webservice , like this one : http://services.hanselandpetal.com/secure/flowers.json

  • 写回答

1条回答 默认 最新

  • douquan9826 2015-02-09 02:49
    关注

    Assuming that you are running apache then the first step will be to enable an authentication module (e.g. mod_auth_basic) which has to be done via your server's .conf file (The exact location depends on your apache installation and other configuration options. )

    After this has been done create a file called .htaccess in the folder which contains your web services which you wish to secure, its contents should be along the lines of (Change the location of AuthUserFile to be where you wish to put the password file. ) it is reccomended that the file is not accessible from the web so in the example below I am assuming that your "web_root" is actually /var/www/htdocs/

    AuthUserFile /var/www/etc/.htpasswd
    AuthType Basic
    AuthName "Secure Files"
    Require valid-user
    

    After this has been performed you have to actually create the password file (replace mynewusername with the username you wish to add, and the location of the file with where you want to create it. but it must match the .htaccess location.)

    htpasswd -c /var/www/etc/.htpasswd mynewusername
    

    After the file has been created then you no longer need the "-c" argument and can simply call:

    htpasswd /var/www/etc/.htpasswd myevennewerusername
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探