-1

This is the content of my html file :

<meta http-equiv="refresh" content="0; url=http://google.com" />

So, when the user open it, it will be redirected to google.. But what I want is write a script inside the file that can change the url/the page that will be loaded every time the user open it.

Example: first time open google second time open facebook and then, start over.. open google, and so on.

Any idea please how can I do that?

Dev
  • 45
  • 11
  • What you're asking for is too broad and unclear. I think that now would be a good time for you to go over the help area if you haven't already https://stackoverflow.com/help and the related links inside it. Read through that and you'll see how things work here on Stack Overflow. It will give you a good idea as to how to formulate a good question, to see what can and should not be asked, as well as what is expected from you. This was made and put into place in order to help (you) have a better and positive experience here on Stack Overflow, which is what everybody wants and aims for. – Funk Forty Niner Sep 15 '18 at 13:06
  • Possible duplicate of [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – Heretic Monkey Sep 15 '18 at 18:13

3 Answers3

1

you could create an array of the urls you require and then use a random number generator to pick one from the array.

<?php
    $urls = array(
      'http://www.facebook.com',
      'http://www.google.com');

    $i = rand(1, (sizeof($urls) - 1));
?>

<meta http-equiv="refresh" content="0; url=<?php echo urls[$i] ?>" />
MartinT
  • 11
  • 1
0

You can use $pagename variable inside <meta http-equiv="refresh" content="0; url=$pagename" /> So the $pagename can be generated from an array list which have multiple pages and randomizing the value you may got the random page.

0

You could randomly select a page in the Javascript but if you want to actually guarantee that it's a different page then you need to create a SESSION so that you can recognize the same visitor again and send them to a different place. As you tagged this PHP, you could do something like this:

<?php

$urls = array(
    'http://google.com',
    'http://yahoo.com',
    'http://bing.com');

session_start();
if(!isset($_SESSION['urlNumber'])) {
    $_SESSION['urlNumber'] = 0;
} else {
    $_SESSION['urlNumber']++;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=<?php echo($urls[$_SESSION['urlNumber']]); ?>" />
</head>
<body>
</body>
</html>

What this does is start a session for each visitor and keep track of which URLs they have gone through by incrementing the session variable on each subsequent visit.

Note, it's not a very good approach. You'd be better sending a HTTP_REDIRECT response from the server. Also, it will break after three URLs because it's run out. You'd want to put a little code in there to reset it back to 0 once it reached the maximum URLs. But that is in line with your approach that you wanted to use.

JaneDoe
  • 310
  • 3
  • 15
  • it's exactly the idea that I looking for, but sadly it's not working .. I don't know why! the link become like this:file:///C:/..../....../Desktop/%3C?%20echo($urls[$_SESSION[%27urlNumber%27]]);%20?%3E – Dev Sep 15 '18 at 13:41