How to do basic authentication on a php CLI

本秂侑毒 提交于 2019-12-02 19:30:39

问题


I have a php script on my server which needs to be run by crun. The domain is protected via basic authentication.

The command: sudo /usr/bin/php -auth=user:mypass /home/www/app_cron/example.php

returns: "not authorized"

due to this code:

if ($settings['auth']['passw'] == true){
    $settings['auth']['users']  = array_keys($settings['auth']['passw']);
    $validated = (in_array($_SERVER['PHP_AUTH_USER'], $settings['auth']['users'])) && ($_SERVER['PHP_AUTH_PW'] == $settings['auth']['passw'][$_SERVER['PHP_AUTH_USER']]);
    if (!$validated) {
      header('WWW-Authenticate: Basic realm="'.$system['page']['name'].'"');
      header('HTTP/1.0 401 Unauthorized');
      die ("Not authorized");
    }
}

This is a pretty old application and I do not want to mess around much

How can I pass parameters to php via CLI in order to authenticate?

来源:https://stackoverflow.com/questions/53546977/how-to-do-basic-authentication-on-a-php-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!