www.webdeveloper.com
Results 1 to 13 of 13

Thread: Random index site

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Question Random index site

    Hello,

    Is it possible to open a random index site when someone visit my domain?
    For example I have index1, index2, index3 and so on. And now I want every time someone visit my homepage that he will be redirected randomly to one of those sites. Is there a way to realize this?

    Thank you very much in advance
    Julian

  2. #2
    Join Date
    Dec 2012
    Posts
    21
    Yes of course. What language do you want to do it in?

    Basically the first thing the page's controller would do is get a random number from 1 to 3 (or however many pages you have the option of), and then redirect to '/index'.$randomNumber by setting a redirect header

  3. #3
    Join Date
    Dec 2012
    Posts
    13
    Or you can include this index<n> pages in index.php without redirecting.

  4. #4
    Join Date
    Nov 2012
    Posts
    450
    Let me try, if it really works..

  5. #5
    Join Date
    Dec 2012
    Posts
    13
    Do you have any interpretator on server?

  6. #6
    Join Date
    Mar 2012
    Posts
    1,497
    In PHP you could do something like:

    <?php
    $i=substr(time(),9,1);
    header( 'Location: http://www.yoursite.com/index'.$i.'.html' ) ;
    exit;
    ?>

    This allows for 10 index files: index0.html to index9.html. It is not strictly random, as it increments at one second intervals from 0 to 9 then back to 0.

    Note: That code MUST be at the very start of the file, which MUST be named '.php', E.g. 'index.php'.

  7. #7
    Join Date
    Dec 2012
    Posts
    13
    But for what we need redirect?
    We need to send page for user only, so we can use:
    include('http://www.yoursite.com/index'.$i.'.html' );
    instead of headers.
    I think that we needn't generate excess traffic?

  8. #8
    Join Date
    Dec 2012
    Location
    Manchester
    Posts
    15
    Thnx Luno for this help. i will definitely back soon if this will work for my sites.

  9. #9
    Join Date
    Mar 2012
    Posts
    1,497
    Good point Luno, I should have thought of that, 'cos I routinely use include files, just not on a "random" basis. Though I'm not sure of the effect on search rating bots of a variable home page, either way??? By the way, if you do substitute include() for header(), remember to remove the exit command as well. That is only needed by the header() command.
    Last edited by jedaisoul; 12-31-2012 at 05:39 AM.

  10. #10
    Join Date
    Dec 2012
    Posts
    13
    But with redirecting we will have the same situation when index.php will empty for search bots.
    It will index index<n> file only.
    If pages have one theme only, we can have index<n> files with BODY of pages only. So we will send header by index.php page (like desctiption, title etc.)

  11. #11
    Join Date
    Mar 2012
    Posts
    1,497
    Yes, I was thinking along those lines. You only need to include the variable content, which is the opposite of what I use include files for: I include the standard content (headers, footers, sidebar etc...) to minimise the maintenance of the site. Update an include file, and every page that uses it changes. Indeed, in this case there is no reason not to do both, i.e. use include files for standard and variable content...

  12. #12
    Join Date
    Dec 2012
    Posts
    13
    "There's more than one way to do it" (r)

    It possible make also without PHP - with using JS.

  13. #13
    Join Date
    Mar 2012
    Posts
    1,497
    True. I prefer PHP.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles