Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-16-2010, 03:29 AM Quick PHP question.
Skilled Talker

Posts: 93
Location: USA
Trades: 0
Code:
<?php

    @include("header.html");
    @include("middle.html");

        if ($_GET["action"]) {
            $includeFile = $_GET["action"] .".php";
                if (@file_exists($includeFile))
                    @include($includeFile);
                else
                    echo "File does not exist!";
        }
        else {
            @include("content.html");
        }

    @include("footer.html");

?>
I use that to call together files to display one of my sites, it works well and makes updating much easier than editing the static HTML files. Makes it a breeze to 'redesign' the site as I can cut a template up into a header, middle, footer and viola!

Anyhow, my question is this. I apologize, its late and I am by no means a PHP scripter. Where it says:

Code:
                    echo "File does not exist!";
How can I get that to display 404.SHTML?

I tried a few different things, buts its 3:30AM my time and I am beat tired. Hoping I can get up in the morning and pick up where I left

TIA
__________________
░▒▓
Please login or register to view this content. Registration is FREE
| Quality Dallas Based Web Hosting Services
░▒▓ Shared, White-Label Reseller, Xen VPS, Dedicated Servers, More
Curtis is offline
Reply With Quote
View Public Profile Visit Curtis's homepage!
 
 
Register now for full access!
Old 05-16-2010, 03:52 AM Re: Quick PHP question.
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
To make 404 response use
PHP Code:
header("HTTP/1.0 404 Not Found",true); 
for more info check
http://php.net/manual/en/function.header.php

To display the 404 document
you can use php include like
PHP Code:
include '404.shtml'
Or if the document you need to display contains server directives you can use SSI
PHP Code:
virtual("/404.shtml"); 
http://php.net/manual/en/function.virtual.php
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-16-2010 at 04:01 AM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-16-2010, 08:14 AM Re: Quick PHP question.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
If you're going to use header, you cannot have any output prior to calling it. So you may want to check if the file exists prior to including 'header.html' and 'middle.html'.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-16-2010, 02:08 PM Re: Quick PHP question.
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
he can if output buffering is enabled.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-18-2010, 05:16 AM Re: Quick PHP question.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
1. You should validate requested "action" BEFORE starting to include/require any template files so that you could decide whether to send regular content or 404 page before starting any output.

2. It is strongly recommended to check allowed "action" not by existing files, but with a kind of predefined array, since file_exists() not only requires filesystem call and can become inefficient under high load but also it presents serious security hole.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-18-2010, 07:34 AM Re: Quick PHP question.
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
As said above, an array of safe words that can be used to call the include would be best. Otherwise you are laying the foundations of an insecure application (and I dont mean an app that hates the mirror!).

PHP Code:
<?php

 
@include("header.html");
    @include(
"middle.html");

        if (
$_GET["action"]) {
            
$includeFile $_GET["action"] .".php";
                if (@
file_exists($includeFile))
                    @include(
$includeFile);
                else
                    @include(
'error404.html');
        }
        else {
            @include(
"content.html");
        }

    @include(
"footer.html");

?>
You could use the above to mimic a 404 responce but control the file included.

Alternativly you could place content.html in the include and have the user redirected to content.html in the event a file dosnt exist but this would be a bad practice without any message explaining why they are seeing a page they didnt expect.

Last edited by Phunk Rabbit; 05-18-2010 at 07:36 AM.. Reason: typo
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 05-18-2010, 01:40 PM Re: Quick PHP question.
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
You could use the above to mimic a 404 responce but control the file included.

Alternativly you could place content.html in the include and have the user redirected to content.html in the event a file doesn't exist but this would be a bad practice without any message explaining why they are seeing a page they didnt expect.
But you should put SE into consideration. SE will need either of 404,301 response to know the requested page is not longer available and should get removed from their index. Showing error404.html without indicating that the page is removed will make search engine index many copies of error404.html pages. which could harm your website or even worse your website may get penalized for having high rate of repeated contents.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-18-2010 at 01:44 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Quick PHP question.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73367 seconds with 12 queries