服务器端包含是否可能具有随机性?
我想在静态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我写问题的最后一部分时,我开始思考如何利用这些时间来做我需要做的事情。我想出了一个可行的解决方案,它绝不是随机的,但它确实以均匀的方式提供一个广告或另一个广告。
因此,如果我们处于前半分钟,这将提供一个版本,如果我们处于后半分钟,则将提供另一个版本。
如果您知道任何不同/更好的方法来做到这一点,请插话!
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.
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!
不,不太可能; SSI 执行此操作的方法是包含或执行服务器端 CGI,或者可能在服务器上运行命令。
首选:
好的,但不是首选:
这很可能未启用:
但是您正在编写一个简短的 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:
OK but not preferred:
This is most likely not enabled:
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.