PHP Switching between two variables equally without using database

与世无争的帅哥 提交于 2019-12-06 14:39:09

But the random method (50/50) should serve both equally, given enough requests.

And it is the simplest solution imho.

<?php
$ad1 = '<img src... >';
$ad2 = '<img src...2 >';

echo mt_rand(0, 1) ? $ad1 : $ad2;
?>
  • You can use memcache (recommended)
  • You can keep track of the last used variable in a file on the server (not recommended)
  • You can use time() and use its mod by 2 as your decision maker (still not an exactly equality as you wanted)

(I think, on the long run, rand will serve you great)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!