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

Link to comment
Share on other sites

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
Share on other sites

<?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
Share on other sites

<?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
Share on other sites

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