Bradley99 Posted January 14, 2011 Share Posted January 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/ Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1159455 Share on other sites More sharing options...
phpfreak Posted January 15, 2011 Share Posted January 15, 2011 The ?page=usersonline is called an argument - you pass arguments into your script and then call the relevant actions based on those arguments... Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1159832 Share on other sites More sharing options...
Bradley99 Posted January 23, 2011 Author Share Posted January 23, 2011 So at the top of each page have a '$page=main' argument? Then in the menu use 'game.php?page=main'? Would that work? Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1163806 Share on other sites More sharing options...
codefossa Posted January 23, 2011 Share Posted January 23, 2011 You are wanting to get a variable from the URL, so we will use $_GET. If it's http://example.com/index.php?page=register then $_GET['page'] is equal to 'register'. if ($_GET['page'] == 'register') { // display registration form // Alternatively require registration page } Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1163914 Share on other sites More sharing options...
blew Posted January 23, 2011 Share Posted January 23, 2011 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' Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1163975 Share on other sites More sharing options...
Simon Mayer Posted January 23, 2011 Share Posted January 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224447-using-phppageindex/#findComment-1164061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.