服务器端包含是否可能具有随机性?

发布于 2024-08-03 04:08:56 字数 398 浏览 2 评论 0原文

我想在静态 html 文件中引入一些随机* 行为。我想尝试两种不同的广告方案,并且希望使用其中一种或另一种随机投放页面。使用脚本语言来生成整个东西似乎有些过分了,所以我认为 SSI 是理想的选择。

我想做这样的事情:

<!--#if expr="shouldIdoA" -->
... do A ...
<!--#else -->
... do B ...
<!--#endif -->

我不确定的部分是如何在 A 或 B 之间做出决定。

* 我真的只是希望它在大约 50% 的时间里以一种方式进行,并且大约 50% 的情况下,真正的随机性并不重要。即使是像确定当前时间的秒部分是偶数还是奇数这样简单的事情也对我有用。

I want to introduce some random* behavior into an otherwise static html file. I want to experiment with two different advertising schemes, and I want to have the page erved randomly with either one or the other. It seems like overkill to use a scripting language to generate the whole thing, so I thought SSI would be ideal.

I want to do something like this:

<!--#if expr="shouldIdoA" -->
... do A ...
<!--#else -->
... do B ...
<!--#endif -->

The part I am not sure about is how to decide between A or B.

* I really just want it to go one way about 50% of the time, and the other way about 50% of the time, so true randomness is not important. Even something as simple as deciding if the seconds part of the current time is even or odd would work for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

瑾夏年华 2024-08-10 04:08:56

当我写问题的最后一部分时,我开始思考如何利用这些时间来做我需要做的事情。我想出了一个可行的解决方案,它绝不是随机的,但它确实以均匀的方式提供一个广告或另一个广告。

<!--#config timefmt='%S' -->
<!--#if expr='$DATE_LOCAL > 30' -->
... do A ...
<!--#else -->
... do B ...
<!--#endif -->

因此,如果我们处于前半分钟,这将提供一个版本,如果我们处于后半分钟,则将提供另一个版本。

如果您知道任何不同/更好的方法来做到这一点,请插话!

As I was writing the last part of my question, I got to thinking about how I could use the time to do what I needed. I came up with a workign solution which is by no means random, but it does serve up one ad or the other, in an even fashion.

<!--#config timefmt='%S' -->
<!--#if expr='$DATE_LOCAL > 30' -->
... do A ...
<!--#else -->
... do B ...
<!--#endif -->

So, this will serve up one version if we are in the first half of the minute, and the other version if we are in the second half of the minute.

Please chime in if you know of any different/better way to do this!

‖放下 2024-08-10 04:08:56

不,不太可能; SSI 执行此操作的方法是包含或执行服务器端 CGI,或者可能在服务器上运行命令。

首选:

<!--#include virtual="/cgi-bin/random-number.cgi?max=1" -->

好的,但不是首选:

<!--#exec cgi="/cgi-bin/random-number.cgi" -->

这很可能未启用:

<!--#exec cmd="perl /inet/cgi-bin/random-number.pl 0 1" -->

但是您正在编写一个简短的 perl 脚本来为您提供一个随机数,而这正是您试图避免的事情。抱歉,如果您确实想避免使用 javascript 或 PHP 进行此操作,那么您的解决方案和变体就足够了。

No, not really possible; the SSI way of doing this would be to include or execute a server-side CGI, or maybe run a command on the server.

Preferred:

<!--#include virtual="/cgi-bin/random-number.cgi?max=1" -->

OK but not preferred:

<!--#exec cgi="/cgi-bin/random-number.cgi" -->

This is most likely not enabled:

<!--#exec cmd="perl /inet/cgi-bin/random-number.pl 0 1" -->

But then you're writing a short perl script to give you a random number, and that's the kind of thing you were trying to avoid anyway. Sorry, but your solution and variants on it were adequate, if you really want to avoid doing it with javascript or PHP.

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