访问 .env 在 PHP 中返回 Uncaught error: Array callback must have exactly two elements

huangapple go评论60阅读模式
英文:

Accessing .env in PHP returns Uncaught error: Array callback must have exactly two elements

问题

I would like to store certain information in a .env, access it in PHP and append that information to my POST request. However, when I try and do that I get the error:

[500]: POST /proxy.php?url=https://www.expensify.com/api?command=Authenticate - Uncaught Error: Array callback must have exactly two elements

It seems I am not actually accessing any .env variables:

$name = $_ENV("NAME");
$password = $_ENV("PASS");
print_r('name', $name);
echo $name;
...
$ch = curl_init();
$userID = $_POST['userID'];
$userSecret = $_POST['userSecret'];
$postData = array(
    $name => $name,
    $password => $password,
    $userID => $userID,
    $userSecret => $userSecret
);
$data = http_build_query($postData);

and in my .env

NAME=***
PASS=***

(Note: The text within backticks is code and should not be translated.)

英文:

I would like to store certain information in a .env, access it in PHP and append that information to my POST request. However, when I try and do that I get the error:

[500]: POST /proxy.php?url=https://www.expensify.com/api?command=Authenticate - Uncaught Error: Array callback must have exactly two elements 

It seems I am not actually accessing any .env variables:

$name= $_ENV("NAME");
$password= $_ENV("PASS");
print_r('name', $name);
echo $name;
...
    $ch = curl_init();
    $userID= $POST['userID'];
    $userSecret = $POST['userSecret'];
    $postData = array(
        $name=>$name,
        $password=>$password,
        $userID=>$userID,
        $userSecret=>$userSecret
    );
    $data = http_build_query($postData);

and in my .env

NAME=***
PASS=***

答案1

得分: 1

$_ENV 是一个数组,但你将它当作函数来调用 $_ENV('NAME')

请使用 $_ENV['NAME']

英文:

$_ENV is array, but you call it as function $_ENV('NAME').

Use $_ENV['NAME']

huangapple
  • 本文由 发表于 2023年2月23日 22:10:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545937.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定