Hey all, I have a problem with php include. I have the following code in include.php <?php // Gather variable data from the URI // eg. filename.php?page=index $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog'; // Determine whether or not the requested file exists if (!file_exists('includes/' . $page . '.php')) { echo "File could not be included, no file exists."; exit; } switch ($page) { case 'blog': include('includes/blog.php'); break; // If no variable is set in the URI, or no case matches, include index default: include('includes/blog.php'); break; } ?> PHP: The i have the following in includes/blog.php hello PHP: but when going to domain.com/include.php?page=blog The page loads blank Can anyone help with this? Thanks
try <?php // Gather variable data from the URI // eg. filename.php?page=index $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog'; // Determine whether or not the requested file exists if (!file_exists('includes/' . $page . '.php')) { echo "File could not be included, no file exists."; exit; } echo $page; switch ($page) { case 'blog': include('includes/blog.php'); break; // If no variable is set in the URI, or no case matches, include index default: include('includes/blog.php'); break; } ?> PHP: and tell us output
Try to see if you can catch an error with error reporting. <?php error_reporting(-1); // Gather variable data from the URI // eg. filename.php?page=index $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog'; // Determine whether or not the requested file exists if (!file_exists('includes/' . $page . '.php')) { echo "File could not be included, no file exists."; exit; } switch ($page) { case 'blog': include('includes/blog.php'); break; // If no variable is set in the URI, or no case matches, include index default: include('includes/blog.php'); break; } ?> PHP: Also, try making sure that includes/blog.php doesn't have to have specific formatting in order to be displayed by replacing your blog.php with the original.
I think he means that the blog.php had to be a certain format to be displayed correctly. I could be wrong but it seems that way.