Jump to content

PHP Navigation in homepage


ev5unleash

Recommended Posts

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

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

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>"; } 
?>

 

 

<?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:

<?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>"; }

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.