如何使用环境变量(repl.it)创建数组?

发布于 2025-02-07 06:03:38 字数 748 浏览 4 评论 0原文

如果您不知道这一点,则环境变量有点像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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玻璃人 2025-02-14 06:03:38

您的环境变量$ loadString作为字符串存储并检索,PHP array()将要创建的数组的所有元素作为参数。因此,数组($ loadString)给出长度1的数组,其中完整的字符串存储在环境变量中是其唯一的元素。

看来您的字符串格式就像一个json数组,但是没有封闭的正方形括号,因此您可以执行此操作:

$items = json_decode('[' . $loadstring . ']');

另请参阅 json_decode 文档。

Your environment variable $loadstring is stored and retrieved as a string, and PHP array() 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:

$items = json_decode('[' . $loadstring . ']');

See also the json_decode documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文