Jump to content

Using .php?page=index


Bradley99

Recommended Posts

Hello,

 

I am coding a new game, but rather than having links like /usersonline.php i would like to have game.php?page=usersonline

I have never done this before so I'm looking for a quick heads up on the basics if possible.

 

Thanks in advance.

 

Brad

 

Google my man

 

Basic:

http://www.w3schools.com/php/php_get.asp

The manual:

http://php.net/manual/en/reserved.variables.get.php

Link to comment
Share on other sites

thats easy... just make a menu and link it to "index.php?page=game"

 

then, make the php code like this

<? php

if ($_GET) {

if ($_GET['page'] == 'game') {

echo "Hey, you are at the game session!";

}
}

 

so, the $_GET must be the same as you put after the "?"  dot...

if you want "index.php?session=game", so $_GET['session'] == 'game'

 

Link to comment
Share on other sites

I would use switch to do this.

 

switch($_GET['page'])
{
  case 'game':
    //game page contents
    break;
  case 'usersonline':
    //usersonline page
    break;
  default:
    //a default page, maybe your homepage, maybe your 404 page
}

 

If you then want to be clever, you can use the include() function to load the required contents and keep your index page small.

 

 

From an SEO point of view, using get arguments is not always a good idea. You might want to consider using .htaccess modrewrite to direct yoursite.com/pagename.php to yoursite.com/index.php?page=pagename so that the site appears to have separate pages.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.