Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-03-2005, 05:41 AM PHP Random
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
Hey.
Is it possible to make a php page as a homepage for a site - that when it is accessed, it chooses one of two HTML pages at random to display? Like, if I entered the site - as soon as I enter, the PHP page chooses at random between Index.html and Index1.html and displays one.
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
 
Register now for full access!
Old 09-03-2005, 06:46 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
index.php

PHP Code:
$rnd mt_rand();
if (
$rnd mt_getrandmax()/) {
    include 
"/pagename.htm";
    } else { 
    include 
"/otherpage.htm";

__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-03-2005, 07:49 AM
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
appreciated
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
Old 09-03-2005, 08:18 AM
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
Ahh it worked! Hooray. But one more thing.. this may sound like a simple question but I've never used PHP. How do I set a .PHP page as my home page? Because, when I build my normal HTML sites I use FrontPage and it just has a "Set as Home Page" thing. Any help would be fantastic.
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
Old 09-03-2005, 09:27 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
just call it index.php

you may need to rename index.htm depending on the order of the default document list.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-04-2005, 01:05 AM
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
Thanks a lot, man! It all works now !!!
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
Old 09-18-2005, 06:51 AM
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
The stuff you have told me all works very well (thanks).
I have another question though (sorry, haha)

I thought originally that I could just add pages to this previous code (see above), but then it didn't work, and I found out it can only randomize between two pages. Is there a way of randomizing between a 2+ number. Will it have to be a different code for every different number of pages - so a different code for randomizing between 5 and a different code for randomizing between 6??

Any help is great
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
Old 09-18-2005, 08:28 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Not a problem.
PHP Code:
<?
$NumOfPages 
6;  // change this value as required.
$rnd mt_rand();
$rndMax mt_getrandmax();
$diff $rndMax $NumOfPages;

for (
$x 1$x <= $NumOfPages$x++) {
    
$diffArray[$x] = round($diff $x);
    }

for (
$x 1$x <= $NumOfPages$x++) {
    if (
$rnd $diffArray[$x]) {
    include 
$x ".php";
    break;
    }
}
?>
calculate the difference for the number of pages by dividing the max by the page count and store it in an array. then step through the array, then include and break when the random number is smaller than the array element.

you need to call your include pages 1 to NumberOfPages with a php extension (i.php to n.php)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-18-2005, 09:48 AM
Dave42's Avatar
Average Talker

Posts: 16
Location: Brisvegas, Australia
Trades: 0
Thanks heaps man. You've been quite helpful!!
I hope this isn't too frustrating - if it is - don't feel you have to answer.
I am a total beginner, and I'm struggling to figure this all out.
I was wondering (remember feel free to say no) if you could type the code to randomize between 3 .htm pages - index1.htm, index2.htm, index3.htm.
And if it's not too much, could you give an example of how I could add an index4.htm on to that if I liked. It's just that I will be adding more index pages later and this could come in handy. Totally up to you - just putting it out there incase. Thanks again!!
__________________
i'll see you at the bitter end
Dave42 is offline
Reply With Quote
View Public Profile Visit Dave42's homepage!
 
Old 09-18-2005, 10:07 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
just change this line
PHP Code:
  include $x ".php"
to
PHP Code:
  include "index" $x ".htm"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to PHP Random
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72737 seconds with 12 queries