Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 29-05-08
Registered User
 
Join Date: Jan 2007
Posts: 223
Thanks: 4
Thanked 3 Times in 3 Posts
hairycornflakes is an unknown quantity at this point
  Need a Script to show a random page

making a website just now and id like to have a button that when pressed shows up a page at random from a predefined list of pages (predefined by me of course!)

im sure this is a relatively simply php script but im lost when it comes to php!

iv tried searching for it, and there seemed to be a script but the page it was hosted on is now showing as an error

any help much appreciated!

hc
__________________
Early to bed and early to rise makes a man healthy, wealthy and wise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 29-05-08
D-Mac's Avatar
Registered User
 
Join Date: Mar 2004
Location: Surrey
Posts: 1,044
Thanks: 10
Thanked 10 Times in 7 Posts
D-Mac is an unknown quantity at this point
  Re: Need a Script to show a random page

You could use the php rand function to generate a random number then use if statements to select the page assigned to each number.
__________________
David Macfarlane
PHP Programming Service for Affiliates | Friendly VAT Calculator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 29-05-08
Registered User
 
Join Date: Jan 2007
Posts: 223
Thanks: 4
Thanked 3 Times in 3 Posts
hairycornflakes is an unknown quantity at this point
  Re: Need a Script to show a random page

see that does make sense to me, but putting that into php would just be mindboggling!

the only php iv ever done is renaming .htm files to .php files lol!

cheers for your post though, im gonna have to learn php at some point!

if some1 can provide a quick script that doesnt take them more than a minute to create then please do :-)

hc
__________________
Early to bed and early to rise makes a man healthy, wealthy and wise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 29-05-08
D-Mac's Avatar
Registered User
 
Join Date: Mar 2004
Location: Surrey
Posts: 1,044
Thanks: 10
Thanked 10 Times in 7 Posts
D-Mac is an unknown quantity at this point
  Re: Need a Script to show a random page

hmm. how do i display code on here?
__________________
David Macfarlane
PHP Programming Service for Affiliates | Friendly VAT Calculator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 29-05-08
D-Mac's Avatar
Registered User
 
Join Date: Mar 2004
Location: Surrey
Posts: 1,044
Thanks: 10
Thanked 10 Times in 7 Posts
D-Mac is an unknown quantity at this point
  Re: Need a Script to show a random page

PHP Code:
<?php
 $pageid 
=  rand(13);
 if (
$pageid == 1){$location "http://www.google.com";}
 else if (
$pageid == 2){$location "http://www.yahoo.com";}
 else if (
$pageid == 3){$location "http://www.msn.com";}
 echo 
"<a href=$location>$location</a>";
?>
__________________
David Macfarlane
PHP Programming Service for Affiliates | Friendly VAT Calculator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 29-05-08
tbp tbp is offline
Registered User
 
Join Date: Dec 2006
Posts: 1,999
Thanks: 0
Thanked 18 Times in 18 Posts
tbp is an unknown quantity at this point
  Re: Need a Script to show a random page

It's actually pretty easy, as D-Mac said.

Basically the rand($x,$y) command gives you a random number between $x and $y eg rand(1,10) would give you a number between (and including) 1 and 10.

At the simplest level you could use the code:

PHP Code:
$x number_of_pages;
$page rand(1,$x);
switch(
$page){
  case 
1:
    
header("Location: page1.php");
    break;
  case 
2:
    
header("Location: page2.php");
    break;
   
etc...

You just need to assign the number of pages to $x, and then do a case statement for each number from 1 to $x, and put your page names in the header() command.

This will redirect to the page corresponding to the randomly generated number.

If you have a list of all your pages in the database, with a CMS for example, there is an sql RANDOM command that will pull a random record from a table.

UPDATE: Oops, D-Mac beat me to it lol
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 29-05-08
Registered User
 
Join Date: Jan 2007
Posts: 223
Thanks: 4
Thanked 3 Times in 3 Posts
hairycornflakes is an unknown quantity at this point
  Re: Need a Script to show a random page

thanks dmac and tbp...

so do i save that code as random.php then make a button that links to random.php?

good work folks!

hc
__________________
Early to bed and early to rise makes a man healthy, wealthy and wise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 29-05-08
D-Mac's Avatar
Registered User
 
Join Date: Mar 2004
Location: Surrey
Posts: 1,044
Thanks: 10
Thanked 10 Times in 7 Posts
D-Mac is an unknown quantity at this point
  Re: Need a Script to show a random page

tbp's code would work the way you describe.
if you use mine you could insert it into the page you are linking from, and change the text in the href to a button
__________________
David Macfarlane
PHP Programming Service for Affiliates | Friendly VAT Calculator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 29-05-08
Registered User
 
Join Date: Jan 2007
Posts: 223
Thanks: 4
Thanked 3 Times in 3 Posts
hairycornflakes is an unknown quantity at this point
  Re: Need a Script to show a random page

would that page then need to be a php page. because as it stands it is an htm page

im almost finishe dmaking up the wee button part, so will give it a bash in a bit and post back my results !
__________________
Early to bed and early to rise makes a man healthy, wealthy and wise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 29-05-08
D-Mac's Avatar
Registered User
 
Join Date: Mar 2004
Location: Surrey
Posts: 1,044
Thanks: 10
Thanked 10 Times in 7 Posts
D-Mac is an unknown quantity at this point
  Re: Need a Script to show a random page

mine would need to be a php page. tbp's could link to random.php from your html page.
__________________
David Macfarlane
PHP Programming Service for Affiliates | Friendly VAT Calculator
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #11 (permalink)  
Old 29-05-08
Registered User
 
Join Date: Jan 2007
Posts: 223
Thanks: 4
Thanked 3 Times in 3 Posts
hairycornflakes is an unknown quantity at this point
  Re: Need a Script to show a random page

thanks folks, got it working perfectly
__________________
Early to bed and early to rise makes a man healthy, wealthy and wise
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote