ev5unleash Posted June 17, 2008 Share Posted June 17, 2008 Okay, I want to use a script like this <?php $page = $_GET["navigate"]; if (!$page) { include "/"; } else if($page=="Home") { include "index.php"; } else if($page=="ahome") { include "aph.html"; } else { echo "<b><h1>PHP Error</h1></b>"; } ?> So I can navigate from the homepage like http://www.example.com/?navigate=ahome and get to the requested page. I can do this now but when people regularly navigate to the website they get Warning: include(/) [function.include]: failed to open stream: No such file or directory in /var/www/index.php on line 48 Warning: include() [function.include]: Failed opening '/' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/index.php on line 48 At the top of the webpage (because it's not navigating anywhere. Anyone have any ideas on how to do this better? Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 17, 2008 Share Posted June 17, 2008 PHP isn't liking where you're trying to include from. <?php define("SERVER_ROOT", $_SERVER['DOCUMENT_ROOT']); // Do your stuff if ($desired=="whatever") { include (SERVER_ROOT."/directory/file.php"); die(); } ?> SERVER_ROOT is defined in all my scripts with the first page that includes all files that need processed, hence why it's a global variable. Try doing something like that Quote Link to comment Share on other sites More sharing options...
ev5unleash Posted June 17, 2008 Author Share Posted June 17, 2008 You mean something like this? Because the one you gave me did not work and nor did this one <?php define("SERVER_ROOT", $_SERVER['DOCUMENT_ROOT']); // Do your stuff <?php $page = $_GET["navigate"]; if (!$page) { include "/"; } else if($page=="Home") { include "index.php"; } else if($page=="Forum") { include "/forum.php"; } else if($page=="ahome") { include "aph.html"; } else { echo "<b><h1>404 Error</h1></b>"; } ?> Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 You are opening php within php. Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 18, 2008 Share Posted June 18, 2008 <?php $page = $_GET["navigate"]; if (!$page) { include "index.php"; } else if($page=="Home") { include "index.php"; } else if($page=="ahome") { include "aph.html"; } else { echo "<b><h1>PHP Error</h1></b>"; } ?> Does that help? D: Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 <?php define("SERVER_ROOT", $_SERVER['DOCUMENT_ROOT']); // Do your stuff $page = $_GET["navigate"]; if (!$page) { // not sure what you're doing here. scrap it. include "/"; } else if($page=="Home") { include(SERVER_ROOT."index.php"); } else if($page=="Forum") { include(SERVER_ROOT."folder/directory/etc/forum.php"); } else if($page=="ahome") { include(SERVER_ROOT."directory/for/this/aph.html"); } else { echo "<b><h1>404 Error</h1></b>"; } ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 18, 2008 Share Posted June 18, 2008 I use this script: <?php // get the page $page = $_GET['page']; // Now, test the URL query for security if ( !is_file ( "lib/$page.php" ) && $page != "" ) { // File not found! header ( "Location: index.php?page=home" ); } // Are you in index? elseif ( $page == "" ) { $page = "home"; } // Calling the specific page require_once( "lib/$page.php" ); ?> Regards ACE Quote Link to comment Share on other sites More sharing options...
ev5unleash Posted June 18, 2008 Author Share Posted June 18, 2008 k thanks 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.