...

View Full Version : I want one php file with all games?



camzenxbt
09-04-2011, 06:08 PM
Hi there,

I'm currently building a flash-based games website and on a different games website I have seen something like this: game.php?id=11 and I have never known how this is done?.

I would like to do this as it would save me time having to make multiple pages for the games.

How is this done?, does it require a database to be done (I'm not botherd if it does, just wondering if it requires one).

Many thanks for any replies!.

tracknut
09-04-2011, 06:43 PM
In its most generic way, it would work like this:


<?php
switch ($_GET['id'])
{
case 1:
// run game 1
break;
case 2:
// run game 2
break;
default:
echo "no game specified";
}
?>

myfayt
09-04-2011, 06:52 PM
Here is another way of doing it.


if (isset($_GET['x']))
{
$x = explode(':', $_GET['x']);

switch($x[0])
{
case 'game1':
game1();
break;

case 'game2':
game2();
break;

}
}

else { menu(); }

So if the script was called menu.php and you go to that, it will load the menu function. To get to the others, you use this menu.php?x=game1

camzenxbt
09-04-2011, 10:37 PM
Thank you for replying!.

So can I use this for as many games as I want? Can I make more cases like case 3 and case 4 and so on?.

tracknut
09-04-2011, 10:55 PM
Thank you for replying!.

So can I use this for as many games as I want? Can I make more cases like case 3 and case 4 and so on?.

Yep!

Dave

camzenxbt
09-05-2011, 04:00 PM
Thank you for your help on this topic!, this code works very good!, ive thanked you for your post aswell :).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum