Jump to content

Making a code to have visible page navigation (?page=example)


DSGamer3002

Recommended Posts

I'm making a site on my local network (using a Mac with web sharing) and I've come to a roadblock. I realize there are multiple ways to make a code like this in which you set up a system where if you put "?page=this&name=that" in the url it makes the page include different .php files. I'm just curious if there's something wrong with the code I'm using, since it isn't including the files I specify in the url.

 

<?php

$games = array('game1', 'game2', 'game3', 'game4', 'game5', 'game6', 'game7', 'game8');

$pages = array('index', 'checklist', 'dataset');

?>

 

(unrelated html here)

 

<?php 

if (in_array($_GET['game'], $games)) {

include ($_SERVER['DOCUMENT_ROOT'] . '/gh/nav_game/' . $_GET['game'] . '.php'); 

} else {

include ($_SERVER['DOCUMENT_ROOT'] . '/gh/nav_game/default_game.php'); 

}

?>

 

(unrelated html here)

 

<?php 

if (in_array($_GET['page'], $pages)) {

include ($_SERVER['DOCUMENT_ROOT'] . '/gh/' . $_GET['game'] . '/' . $_GET['page'] . '.php'); 

} else {

include ($_SERVER['DOCUMENT_ROOT'] . '/gh/' . $_GET['game'] . '/index.php'); 

}

?>

 

 

Should I be doing something different, or is this easily fixable? Or does this have to do with using PHP on a web sharing localhost?

Link to comment
Share on other sites

Your first debug action should be to make sure that the url parameters are found in the array or not:

 

if (in_array($_GET['game'], $games)) {

   print "game is in array";

} else {

   print "game not found in array";

}

 

Also try echoing out the contents of $_SERVER['DOCUMENT_ROOT'] . '/gh/nav_game/' . $_GET['game'] . '.php' to make sure that the filepath it's eventually trying to use is what you expect.

 

Do you always get the default game page, or does something else happen?

Link to comment
Share on other sites

I tried your debug and all the arrays are working fine for both pages and games.

 

What's happening is that it's not including ANYTHING. I look in the source code and it's just a big blank space between the HTML where it should be including the other files. Could the $_SERVER['DOCUMENT_ROOT'] thing be relocating it to a different directory, or what else would cause this?

Link to comment
Share on other sites

$_SERVER['DOCUMENT_ROOT'] might not be what you expect - try echoing out

 

$_SERVER['DOCUMENT_ROOT'] . '/gh/nav_game/' . $_GET['game'] . '.php'

 

And its variations and check that the filepath it thinks it's looking for is the same filepath that you think it should be looking for.

Link to comment
Share on other sites

$_SERVER['DOCUMENT_ROOT'] might not be what you expect - try echoing out

 

$_SERVER['DOCUMENT_ROOT'] . '/gh/nav_game/' . $_GET['game'] . '.php'

 

And its variations and check that the filepath it thinks it's looking for is the same filepath that you think it should be looking for.

 

Yep, it was trying to locate a completely different directory. Fixed it now. Thanks. ^_^

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.