• 0

Handling a missing PHP include


Question

Hi folks,

I'm normally work with CFML but I've started to dig deeper into PHP.

I've been using the function "include" to pull in pages and I can't seem to find any information about a feature I need. I'm passing a variable in the URL containing information about what page I want to show:

include("pages/".$page.".php");

But if a page is requested that doesn't exist or a false variable is entered in the URL I want a specific page to be shown.

How do I pass a default variable like $page=main to output the main.php page. I know it can be done since the Neowin site does this for example.

Thanks...

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

well...

you have severa possibilities how to do that. the simplest is to check if file exists and the if yes, include it,..




// lets check if file exists first (php func: is_file (); )

if (is_file ("pages/". $page .".php"))

{

  include ("pages/". $page .".php")

}



// if file doesn't exists we do this

else

{

  $page = "main";

  include ("pages/". $page .".php")

}

that will do... does it work?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.