SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2008
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display Different Pages On Main Site

    What I would like to do is instead of displaying 1 page on www.site.com I want it to display www.site.com/page1 or www.site.com/page2..www.site.com/page3. Just basically trying to get the main page to rotate between sub pages without changing the URL on my site when the page is refreshed. How do I do this?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $pages = array('page1.php''page2.php''page3.php');
    include 
    $pages[array_rand($pages)]; 
    This will not rotate in a sequence. The same page may be shown many times in a row due to it being random.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2008
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    PHP Code:
    $pages = array('page1.php''page2.php''page3.php');
    include 
    $pages[array_rand($pages)]; 
    This will not rotate in a sequence. The same page may be shown many times in a row due to it being random.
    Thanks! Is this random per person (if they refresh) or for anyone that visits the site (random each time theres a new ip)?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's random per page request. It has no notion of a unique visitor or ip or anything like that. If you wanted it to cycle through the list on a per visitor basis, you could use cookies
    PHP Code:
    $pages = array('page1.php''page2.php''page3.php'); 

    if (isset(
    $_COOKIE['last_viewed'])) { 
        
    $last_viewed abs((int) $_COOKIE['last_viewed']); 
    } else { 
        
    $last_viewed array_rand($pages); 


    $index = ($last_viewed 1) % count($pages);
    setcookie('last_viewed'$index);
    include 
    $pages[$index]; 

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2009
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If someone refreshes the page they will get the random page. Eventually they will see all three.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •