英文:
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']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论