PHP Get Page Code Help, Attempting to get a random page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RCline
Forum Newbie
Posts: 2
Joined: Sun Aug 12, 2007 11:32 am

PHP Get Page Code Help, Attempting to get a random page.

Post by RCline »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok. I wish I knew how to search for this in the forum, but I don't know what this little set of code is called. I'm attempting to load a random HTML page from a small group of files I have. When this script runs it appears to grab my RANDOM.html page (good), but once it hits the script I'm running in RANDOM.html, it loads the one of the files from the group into a new window. Anyway...Here's the little code that I'm using:

Code: Select all

<?php $page = $_GET['Page'];?>
then...I have this code in a cell for the content to be loaded.

Code: Select all

<?php
              if ($page == "arche") {
               include("arche.html");
             }

             elseif ($page == "bolo") {
			  include("bolo.html");
			 }
			 
			 elseif ($page == "contact") {
			   include("contact.html");
			 }
		
			 else {include("RANDOM.html");}
            ?>
the script in RANDOM.html is this:

Code: Select all

<SCRIPT LANGUAGE="JavaScript">


var howMany = 2;  // max number of items listed below
var page = new Array(howMany+1);

page[0]="a.html";
page[1]="b.html";
page[2]="c.html";

function rndnumber(){
var randscript = -1;
while (randscript < 0 || randscript > howMany || isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1));
}
return randscript;
}
quo = rndnumber();
quox = page[quo];
window.location=(quox);
</SCRIPT>
Because my script doesn't tell it to load into that particular cell, is why I'm getting the new page I suppose.

So I guess my question is this: Can I marry the 2 scripts together?

I really appreciate any help on this. I'm not a programmer by any means. So if you decide to help me out, please consider the person you are replying to has been kicked in the head repeatedly by a muel.

Thank you for your help.

Roger


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

This sounds like a JavaScript question, not a PHP question.
However, I think you could easily simulate that script with PHP.

Instead of 'include("RANDOM.html");'...

Code: Select all

$validPages = array("a.html", "b.html", "c.html");
include $validPages[mt_rand(0, sizeof($validPages) - 1)];
RCline
Forum Newbie
Posts: 2
Joined: Sun Aug 12, 2007 11:32 am

Post by RCline »

Are you kidding me? THAT'S AWESOME!!!

Thank you, thank you, thank you.
Post Reply