简体   繁体   English

当用户进入主页(index.php)时,如何显示用户随机子网页?

[英]How can I show the user random subwebpage when he enters my main page (index.php)?

I have a domain registered, eg mydomain.com . 我注册了一个域,例如mydomain.com。 I would like to put there some php page (or whatever - html with jquery?, etc?) that would have a small script - when user enters this page, he will be immediately randomly redirected to one of my subpages (that are also on the same level as index.php, for example first.php, second.php, third.php) - is that achievable? 我想在此放置一些php页面(或其他内容-带有jQuery的html等),当用户进入此页面时,他将立即被随机重定向到我的一个子页面(该页面也位于与index.php处于同一级别,例如first.php,second.php,third.php)-可以实现吗?

How about a javascript solution: javascript解决方案如何:

  var webpages = ['url1', 'url2', 'url3'];
  //you can have an array of the urls

  var randomIndex = Math.floor(Math.random() * webpages.length - 1);
  //then generate a valid random index

  window.location.href = webpages[randomIndex];
  //redirect to a subpage randomly

This would scan a directory using php, pick a random file in the directory, and redirect to it. 这将使用php扫描目录,在目录中选择一个随机文件,然后重定向到该目录。 You'd need to make sure everything in the folder was ok to redirect to. 您需要确保文件夹中的所有内容都可以重定向到。

$dir    = '/subpages';
$pages = scandir($dir);
$randomPage=$pages[rand(0,sizeof($pages)];
header('Location: http://example.com/'.$randomPage);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeigniter-当用户键入index.php时显示404页 - Codeigniter - Show 404 Page when User Types index.php 当用户请求index.php / blahblahblah时,显示“找不到页面” - Show “page not found” when user requests index.php/blahblahblah 如何在 PHP 中处理子文件夹的 index.php 作为主 index.php - How can I handle in PHP a subfolder's index.php as main index.php 输入用户ID时如何将用户重定向到他的目录 - How can I redirect user to his directory when he enters his ID 在用户登录 php 后,我如何成功地将用户重定向到他所在的位置(他的当前页面)? - how can i successfully redirect user to where he was(his current page) after he logged in in php? 如何使用grunt缩小index.php? - How can I minify my index.php using grunt? 如何在结帐页面后将用户重定向回 index.php? - How to redirect user back to index.php after checkout page? 当我打开 index.php 页面时,它打开显示底部 - When I open my index.php page, it opens showing the bottom 如何停止我的index.php对每个用户运行两次 - How do I stop my index.php being run twice for every user 在PHP中,我如何将表单数据发送到页面,但是当用户单击“提交”按钮时却将用户定向到另一个页面? - In PHP how do I send form data to a page but direct the user to another when he clicks the submit button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM