如何使用环境变量(repl.it)创建数组?
如果您不知道这一点,则环境变量有点像replion中的秘密价值。
我有一组键我想隐藏在网站上,我希望该网站随机将密钥选择随机分配给页面加载时的用户。一种临时密钥系统。
但是,一旦我将钥匙值放入环境变量,然后尝试将其加载到数组中,这发生了: https://i.sstatic.net/tiszm.png
在基础上,这是我正在使用的代码(我加载了可变价$ trolliTem,以稍后在代码中显示,但这只是一个html设计)
<?php
$loadstring = getenv('cheatxkeys');
$items = array($loadstring);
$trollitem = $items[array_rand($items)];
?>
,最后,这就是我的环境变量的外观: https:///i.sstatic。 net/naqa6.png
出于明显的原因,这些不是我正在使用的实际密钥代码,而是随机生成的密钥代码量以显示我要做的事情。
如果我的帖子尚不清楚,请发表评论,我真的很想让它正常工作。谢谢!
If you're not aware of this, environment variables are kind of like secret values in Repl.it as Repl.it makes your code publicly available for everybody.
I have a set of keys that I want to remain hidden on the website, and I want the website to randomize a key selection to distribute to the user on page load. Kind of a makeshift key system.
However, once I put the key values into the environment variable, and I try to load it into an array, this happens: https://i.sstatic.net/TiSzm.png
This, in basis, is the code I'm using (I load the varaible $trollitem for display later on in the code, but that's just a bunch of HTML design)
<?php
$loadstring = getenv('cheatxkeys');
$items = array($loadstring);
$trollitem = $items[array_rand($items)];
?>
And finally, this is how my environment variable looks: https://i.sstatic.net/nAqA6.png
For obvious reasons, these are not the actual key codes I'm using, but rather a randomly generated amount of key codes to show what I'm trying to do.
If my post is unclear, please just comment, I really want to get this to work properly. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的环境变量
$ loadString
作为字符串存储并检索,PHParray()
将要创建的数组的所有元素作为参数。因此,数组($ loadString)
给出长度1的数组,其中完整的字符串存储在环境变量中是其唯一的元素。看来您的字符串格式就像一个json数组,但是没有封闭的正方形括号,因此您可以执行此操作:
另请参阅
json_decode
文档。Your environment variable
$loadstring
is stored and retrieved as a string, and PHParray()
takes as parameters all the elements of the array to be created. Therefore,array($loadstring)
gives an array of length 1 with the full string stored in the environment variable as its only element.It appears your string format is like a JSON array, but without the enclosing square brackets, so you can do this:
See also the
json_decode
documentation.