[PHP] PHP includes instead of Iframes
PHP includes are sometimes used instead of iframes it makes another page appear as though it is actually on the page similar to iframes without all of the scrollbars right making a php include is pretty basic
PHP Code:
<?php
include ('yourpage.php');
?>
rite to make the include change without having to make loads of the same page is a bit more complicated
were you want your include to appear put this code
PHP Code:
<?php
$_GET['page'];
switch($page)
{
case "home":
include('home.php');
break;
case "news":
include('news.php');
break;
case "tutorials":
include('tutorials.php');
break;
case "contact":
include('contact.php');
break;
case "sitemap":
include('sitemap.php');
break;
case "admin":
include('admin.php');
break;
default:
include('home.php');
break;
}
?>
you can change all of the
PHP Code:
case "admin":
include('admin.php');
break;
to the directory of the pages you want and you can also change the name (next to 'case' )
and what you want the default page to be
PHP Code:
default:
include('home.php');
break;
now to make the links which will change the include use this:
HTML Code:
<a href="index.php?page=home">Home</a>
this would change the include to the page with the 'case' called home
to see an example of this www.xenigma.co.uk
*** Updated ***
I have discovered a new way to use php includes were you do not have to add
PHP Code:
case "admin":
include('admin.php');
break;
everytime to use a new page, the code:
PHP Code:
<?php
if (!isset($page))
{
include("pages/home.php");
}
if(file_exists($_GET['page'].".php")){
include $_GET['page'].'.php';
}
if(file_exists($_GET['page'].".html")){
include $_GET['page'].'.html';
}
if(file_exists($_GET['page'].".txt")){
include $_GET['page'].'.txt';
}
elseif (isset($page) && !@include("$page"))
{
echo "Error Page not found!";
}
?>
now the code broken down and the meanings
starts the php script
PHP Code:
if (!isset($page))
{
include("pages/home.php");
}
this part sets what the starting page will be example look at the www.xenigma.co.uk index page there is a description of what was used to develop the site and who it is owned by this is the starting page
PHP Code:
if(file_exists($_GET['page'].".php")){
include $_GET['page'].'.php';
}
if(file_exists($_GET['page'].".html")){
include $_GET['page'].'.html';
}
if(file_exists($_GET['page'].".txt")){
include $_GET['page'].'.txt';
}
this sets what file extensions can be used when searching for them
PHP Code:
elseif (isset($page) && !@include("$page"))
{
echo "Error Page not found!";
}
this is what message will be displayed if the page doesnt exist,
this ends the php script. Now you can display any page were the include is, all as you need to do now is use the file name example in a link
index.php?page=pages/contact/contact that would open in the include either
pages/contact/contact.php
or
pages/contact/contact.html
or
pages/contact/contact.txt