DSGamer3002 Posted September 26, 2009 Share Posted September 26, 2009 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? Quote Link to comment Share on other sites More sharing options...
bothwell Posted September 26, 2009 Share Posted September 26, 2009 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? Quote Link to comment Share on other sites More sharing options...
DSGamer3002 Posted September 27, 2009 Author Share Posted September 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
bothwell Posted September 27, 2009 Share Posted September 27, 2009 $_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. Quote Link to comment Share on other sites More sharing options...
DSGamer3002 Posted September 27, 2009 Author Share Posted September 27, 2009 $_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. Quote Link to comment Share on other sites More sharing options...
bothwell Posted September 27, 2009 Share Posted September 27, 2009 No problem - file paths are a reasonably frequent 'gotcha' for me, to the extent that I'll often specifically define WWW_ROOT in a config file so I can just prepend any file declarations with it. Quote Link to comment 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.