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? Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/ 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 Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567591 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567604 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 You are opening php within php. Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567921 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: Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567925 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567928 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 Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-567963 Share on other sites More sharing options...
ev5unleash Posted June 18, 2008 Author Share Posted June 18, 2008 k thanks Link to comment https://forums.phpfreaks.com/topic/110635-php-navigation-in-homepage/#findComment-568582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.