View Full Version : Can anyone take a look at this please!
Bonxy
05-07-2008, 11:06 PM
i cant get this f'in include to work properly.
can anyone help plz
the page is called testing btw.
www.bonxy.co.uk/testing.php
and here is the code...
<center>
<a href="testing.php?page=home">Home</a> 1
<a href="testing.php?page=blog">blog</a> 1
<a href="testing.php?page=ch">ch</a>
<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php
$_GET['page'];
switch($page)
{
case "home":
include('pages/home.php');
break;
case "blog":
include('blog.php');
break;
case "ch":
include('ch.php');
break;
default:
include('pages/home.php');
break;
}
?>
any help will be greatful.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
chrisgocrazyH
05-07-2008, 11:19 PM
Links:
<a href="testing.php?page=home">Home</a> 1
<a href="testing.php?page=blog">blog</a> 1
<a href="testing.php?page=ch">ch</a>
&
make ur content scipt this:
<?php
$page = $_GET['page'];
if(!isset($page))
{
include("home.php");//Home page..
}
else if(file_exists("" . $page . ".php"))
{
include("" . $page . ".php");
}
else
{
echo("<h1>Error..</h1>The file <strong>" . $page . ".php</strong> was not found.");
}
?>
Protege
05-07-2008, 11:40 PM
<?php
$page = $_GET['page'];
if(!isset($page))
{
include("home.php");//Home page..
}
else if(file_exists("" . $page . ".php"))
{
include("" . $page . ".php");
}
else
{
echo("<h1>Error..</h1>The file <strong>" . $page . ".php</strong> was not found.");
}
?>Don't know why you did double double quotes... lols This will also work, but I believe his version will too...
<?php
if ( $_GET [ 'page' ] === '' )
{
include( 'home.php' );
}
elseif ( $_GET [ 'page' ] !== '' )
{
if ( isset ( $_GET [ 'page' ] ) )
{
if ( file_exists ( $_GET [ 'page' ] . '.php' ) )
{
include ( $_GET [ 'page' ] . '.php' );
}
else
{
echo ( '404, page wasn\'t located' );
// include ( '404.html' );
}
}
}
?>Though the method you want to do using switch can be also used.
<?php
$_GET['page'];
switch($page)
{
case "home":
include('pages/home.php');
break;
case "blog":
include('blog.php');
break;
case "ch":
include('ch.php');
break;
default:
include('pages/home.php');
break;
}
?> I do a clean version for you;
<?php
switch ( $_GET [ 'page' ] )
{
case 'home':
include ( 'pages/home.php' );
break;
case 'blog':
include ( 'blog.php' );
break;
case 'ch':
include ( 'ch.php' );
break;
default:
include ( 'pages/home.php' );
}
?>or... I do it this way..
<?php
$pages_allowed = array ( 'home',
'blog',
'ch'
);
if ( $_GET [ 'page' ] === '' )
{
include ( 'home.php' );
}
elseif ( $_GET [ 'page' ] !== '' )
{
for ( $i = 0; $i <= sizeof ( $pages_allowed ); $i++ );
{
if ( $pages_allowed [ $i ] === ( $_GET [ 'page' ] ) || ( $_POST [ 'page' ] ) )
{
if ( file_exists ( $pages_allowed [ $i ] . '.php' ) )
{
// It should exist as we allowed it in our list etc but yeah.
include ( $pages_allowed [ $i ] . '.php' );
}
else
{
echo ( '404, page wasn\'t located' );
// include ( '404.html' );
}
}
else
{
echo ( 'The page you requested is not in our allowed list! or 404' );
}
}
}
?>
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.