View Full Version : PHP Includes
Shibby-Shabs
04-10-2009, 06:10 AM
I finally figured it out and then I found out i need more help. I have this code but how can I make it so when index.php is opened it automatically shows home.php in where its placed, It currently does that but then every page that I open has that at the top.
<?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!";
}
?>
Verrou
04-10-2009, 06:28 AM
http://www.habboxforum.com/showthread.php?t=43037
Search the forum before you post.
Shibby-Shabs
04-10-2009, 06:33 AM
Yes but that doesn't solve my problem :D
BoyBetterKnow
04-10-2009, 09:41 AM
ummm
You want to redirect index.php to home.php?
header('Location:home.php');
Put that on index.php right after <?php
Shibby-Shabs
04-10-2009, 12:50 PM
ummm
You want to redirect index.php to home.php?
header('Location:home.php');
Put that on index.php right after <?php
Tried it then and it doesn't work:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\jack1\index.php:27) in C:\xampp\htdocs\jack1\index.php on line 28
Jamesy
04-10-2009, 01:09 PM
you need to put it before the <head></head> tags
Source
04-10-2009, 01:33 PM
<?php
$page = $_GET['page'];
$folder = 'pages';
$extension = '.php';
if( isset($page) )
{
$pageInc = $folder . '/' . $page . $extension;
if( is_readable( $pageInc ) )
{
include $pageInc;
}
else
{
echo 'Page not found, sorry!';
// or include a 404 page.
}
}
else
{
include $folder . '/home.php';
}
?>
Really crude, but I think that's what you want. Just make sure you set the folder relative to the php file and the extension. This is only base code, it is important that you should check you want the user to open the requested page otherwise they can potentially request "../index" and caus a never-ending loop.
However, give that a try.
Shibby-Shabs
05-10-2009, 02:31 AM
thanks source, It works so now I can get on with my site.. +REP !
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.