• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

php question?

No problems i understand what you mean, so you do not have to add each page into the script? so you could get the files about, news, results etc under the 1 script without adding anything?

I used the same script as you provided but received the following error on the index page for some reason. :devious2:

Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/sammie/public_html/testing99/index.php on line 15

Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/sammie/public_html/testing99/index.php on line 15

Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/sammie/public_html/testing99/index.php on line 15
 
ok. now they're all in the news folder

<?php

$array = array("dp"=>"new-dp.gif","about"=>"about.php");

if(isset($array[$_GET['page']])){

include_once($array[$_GET['page']]);

}else{

include_once('about.php');

}
?>

that will work.

:)
 
No problems i understand what you mean, so you do not have to add each page into the script? so you could get the files about, news, results etc under the 1 script without adding anything?

I used the same script as you provided but received the following error on the index page for some reason. :devious2:

Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/sammie/public_html/testing99/index.php on line 15

Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/sammie/public_html/testing99/index.php on line 15

Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/sammie/public_html/testing99/index.php on line 15


Ok to remove that error:

find this line:
include"index.php" or die("The was an error in the script on the default page");

change it to

include"index.php";
 
JohnN That code is working, however when going to ?page=about is there any way of removing the index text from that page? or would i be required to set up a blank page and have the script on?

Also what do i do withe the following link of code? what can i change the about.php to?

include_once('about.php');

nwhstaff

Ermm i've just done what you said and i am getting a Fatal error

HTML:
Fatal error: Out of memory (allocated 20709376) (tried to allocate 18 bytes) in /home/sammie/public_html/testing99/index.php on line 9

HTML:
<? 
$page = $_GET['page'];
if(isset($page))
{
ini_set("display_errors","off");
$directory = ""; //The directory where the files will be strored to get , eg. if this file was in a directory called news and the files you want to go are in news/include you will put include inside this variable but if it's in the same directory leave it blank.

$fileget = $directory.$page.".php"; //Structure of directory, ONLY EDIT IF FILES ARE NOT .PHP
$thefile = file_get_contents($fileget) or die("The specified file was not found"); //Gets the contents

echo $thefile; //Shows what was found in that file
}
else
{
include"index.php";
}
?>
 
<?
$page = $_GET['page'];
if(isset($page))
{
ini_set("display_errors","off");
$directory = ""; //The directory where the files will be strored to get , eg. if this file was in a directory called news and the files you want to go are in news/include you will put include inside this variable but if it's in the same directory leave it blank.

$fileget = $directory.$page.".php"; //Structure of directory, ONLY EDIT IF FILES ARE NOT .PHP
$thefile = file_get_contents($fileget) or die("The specified file was not found"); //Gets the contents

echo $thefile; //Shows what was found in that file
}
else
{
include"index.php";
}
?>

^^ your trying to include index.php from index.php and thus causing an infinite loop.

sammie:

<?php

$array = array("dp"=>"new-dp.gif","about"=>"about.php");

if(isset($array[$_GET['page']])){

include_once($array[$_GET['page']]);

}else{

include_once('index_body.php');

}
?>

have ONLY that code in index.php, then make a page called index_body.php and put the content you want to appear by default in there.

hope this helps everyone.
 
to use nwhstaff's code instead do this:

<?
$page = $_GET['page'];
if(isset($page))
{
$directory = ""; //The directory where the files will be strored to get , eg. if this file was in a directory called news and the files you want to go are in news/include you will put include inside this variable but if it's in the same directory leave it blank.

$fileget = $directory.$page.".php"; //Structure of directory, ONLY EDIT IF FILES ARE NOT .PHP
$thefile = file_get_contents($fileget) or die("The specified file was not found"); //Gets the contents

echo $thefile; //Shows what was found in that file
}
else
{
?>

DEFAULT CONTENT GOES HERE!

<?php
}
?>
 
Cheers JohnN, now i understand the coding more, i think i'll be using the coding you have provided as it's more suitable for what i am doing, ie i don't have all files in the one directory but will keep nwhstaff's code also and use it one day. :)
 
Back
Top