PDA

View Full Version : PHP Includes help



Jack!
15-09-2009, 02:47 PM
Hello, for my site i use PHP Includes but, when you go to the site it displayes my 404 page, but i want it to display my home page, but it wont,

please help

my code:


<?php
// File include by Blob off of HabboxForum
$config = array("default" => "home.php", // Default Page (with trailing .php)
"directory" => "pages/", // Directory where files are held (with trailing slash)
"restricted" => array( "index" ), // Restricted pages
"404" => "404.php" // Error Page (with trailing .php)
);
$page = str_replace("/", "", ( ( ( in_array( $_GET["page"], $config["restricted"] ) ) !== false ) ? "home" : $_GET["page"] ) );
( file_exists( $config["directory"] . $page . ".php" ) !== false ) ? include( $config["directory"] . $page . ".php" ) : include( $config["directory"] . $config["404"] );
?>

you can view it in action at

http://www.dfiles.co.cc/site

ThisNameWillDo!
15-09-2009, 02:54 PM
Try this buddy:

<?php
// File include by Blob off of HabboxForum
$config = array("default" => "home.php", // Default Page (with trailing .php)
"directory" => "/site/", // Directory where files are held (with trailing slash)
"restricted" => array( "index" ), // Restricted pages
"404" => "404.php" // Error Page (with trailing .php)
);
$page = str_replace("/", "", ( ( ( in_array( $_GET["page"], $config["restricted"] ) ) !== false ) ? "home" : $_GET["page"] ) );
( file_exists( $config["directory"] . $page . ".php" ) !== false ) ? include( $config["directory"] . $page . ".php" ) : include( $config["directory"] . $config["404"] );
?>

Jack!
15-09-2009, 03:06 PM
everything else works fine, its not the folder locations

ThisNameWillDo!
15-09-2009, 03:07 PM
everything else works fine, its not the folder locations

I believe it is, as currently you have the directory as /pages/, yet you do not even have a pages folder. Just try mine and tell me if it works, it should do.

Jack!
15-09-2009, 03:09 PM
i do have a pages folder, all of the pages are in it...

EDIT:

tried yours got this:


Warning: include(/site/404.php) [function.include (http://dfiles.co.cc/site/function.include)]: failed to open stream: No such file or directory in /home/dfilesco/public_html/site/index.php on line 38

Warning: include() [function.include (http://dfiles.co.cc/site/function.include)]: Failed opening '/site/404.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dfilesco/public_html/site/index.php on line 38

ThisNameWillDo!
15-09-2009, 03:11 PM
Strange, it wasn't showing up that you did earlier, yet now it's showing up.

ThisNameWillDo!
15-09-2009, 03:14 PM
i do have a pages folder, all of the pages are in it...

EDIT:

tried yours got this:


Warning: include(/site/404.php) [function.include (http://dfiles.co.cc/site/function.include)]: failed to open stream: No such file or directory in /home/dfilesco/public_html/site/index.php on line 38

Warning: include() [function.include (http://dfiles.co.cc/site/function.include)]: Failed opening '/site/404.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dfilesco/public_html/site/index.php on line 38

It is showing this error because your 404.php file is not in the /site/ folder, if you moved that to there then it would probably work.

Jack!
15-09-2009, 03:15 PM
my 404 is in the site folder, www.dfiles.co.cc/site/404.php

weird, all my pages are in it and always have been.

been a bit weird recenlty like my 404 disapering then reapearing

ThisNameWillDo!
15-09-2009, 03:16 PM
Yes, your /pages/ folder disappeared on me just now, yet now it is showing again. I don't understand.

The requested URL /site/404.php was not found on this server.

Jack!
15-09-2009, 03:19 PM
try again

ThisNameWillDo!
15-09-2009, 03:20 PM
try again

Yeah it's there now, now try putting my correction in the code in again and it should work.

Jack!
15-09-2009, 03:22 PM
ok will do

edit:

didnt work

ThisNameWillDo!
15-09-2009, 03:26 PM
ok will do

I can see that the error is still coming up, perhaps you have the permissions set incorrectly in the file? I'm sure it is going to the correct page, yet it is still saying it cannot open it. Do you know how to change permissions? Make sure they're set to 0644. Perhaps you have it so world can't read it or something.

Jack!
15-09-2009, 03:30 PM
my pages are in

/site/pages

my 404.php is in

/site

and

/site/pages

ThisNameWillDo!
15-09-2009, 03:31 PM
Edit: Scratch this.

Jack!
15-09-2009, 03:33 PM
but what about when the other pages load?

ThisNameWillDo!
15-09-2009, 03:37 PM
but what about when the other pages load?

I'm very confused. If the directory & pages are there, then it should be able to display the home.php page. Are you sure the permissions are set correctly. I'm not a PHP expert or anything, but I'm pretty sure.

Jack!
15-09-2009, 03:40 PM
what im trying to say is, the code i currently have lets me load the pages, but it wont load home.php when you go onto the site

My pages are in /pages and they work fine i dont need to touch that big just where it is ment to load home

Blob
15-09-2009, 06:30 PM
<?php
// File include by Blob off of HabboxForum
$config = array("default" => "home", // Default Page
"directory" => "pages/", // Directory where files are held (with trailing slash)
"restricted" => array( "index" ), // Restricted pages
"404" => "404.php" // Error Page (with trailing .php)
);
$page = ( ( $_GET["page"] ) === null ) ? $config["default"] : ( str_replace("/", "", ( ( ( in_array( $_GET["page"], $config["restricted"] ) ) !== false ) ? $config["default"] : $_GET["page"] ) ) );
( file_exists( $config["directory"] . $page . ".php" ) !== false ) ? include( $config["directory"] . $page . ".php" ) : include( $config["directory"] . $config["404"] );
?>

Want to hide these adverts? Register an account for free!