Web Analytics Made Easy -
StatCounter I want one php file with all games? - CodingForum

Announcement

Collapse
No announcement yet.

I want one php file with all games?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I want one php file with all games?

    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!.

  • #2
    In its most generic way, it would work like this:
    PHP Code:
    <?php
    switch ($_GET['id'])
    {
    case 
    1:
    // run game 1
    break;
    case 
    2:
    // run game 2
    break;
    default:
    echo 
    "no game specified";
    }
    ?>

    Comment


    • #3
      Here is another way of doing it.

      PHP Code:
      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
      Been a sign maker for 8 years. My business:
      American Made Signs

      Comment


      • #4
        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?.

        Comment


        • #5
          Originally posted by camzenxbt View Post
          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

          Comment


          • #6
            Thank you for your help on this topic!, this code works very good!, ive thanked you for your post aswell .
            Last edited by camzenxbt; Sep 5, 2011, 11:11 AM.

            Comment

            Working...
            X