TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 10-16-2007, 01:06 AM   #1 (permalink)
The Contributor
 
Join Date: Sep 2007
Posts: 89
Thanks: 1
Sam Granger is on a distinguished road
Default Do not allow direct access to php file.

Hey guys!

I have an index.php file with some includes. How do I allow index.php to include the files, but when you try and view the included files outside of index.php, you get an error?

Looking forward to suggestions on how to achieve this! :)
Sam Granger is offline  
Reply With Quote
Old 10-16-2007, 01:29 AM   #2 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 349
Thanks: 24
Haris is on a distinguished road
Default

Example code?
Haris is offline  
Reply With Quote
Old 10-16-2007, 03:39 AM   #3 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

Try this...


Put into page that is including external php page:
PHP Code:
<?php
// Def Constant
define'parentFile' );

// Load Functions
include('includedfile.php');
?>
Put this into the 'includedfile.php' page:
PHP Code:
<?php
/**
* Check For Constant.
*/
defined'parentFile' ) or die( 'oh noes' );
?>
Pretty basic way of doing it. Works though.

Last edited by obolus : 10-16-2007 at 03:41 AM. Reason: bleh
obolus is offline  
Reply With Quote
Old 10-16-2007, 09:29 AM   #4 (permalink)
The Contributor
 
Join Date: Sep 2007
Posts: 89
Thanks: 1
Sam Granger is on a distinguished road
Default

Quote:
Originally Posted by obolus View Post
Try this...


Put into page that is including external php page:
PHP Code:
<?php
// Def Constant
define'parentFile' );

// Load Functions
include('includedfile.php');
?>
Put this into the 'includedfile.php' page:
PHP Code:
<?php
/**
* Check For Constant.
*/
defined'parentFile' ) or die( 'oh noes' );
?>
Pretty basic way of doing it. Works though.
Thanks, will give that a go. :)
Sam Granger is offline  
Reply With Quote
Old 10-17-2007, 01:48 PM   #5 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 650
Thanks: 82
Tanax is on a distinguished road
Default

But if they view index.php, and then views the includedfile.php after, the const is already defined.. so they will be able to view it after if they view index.php first.. true?
Tanax is offline  
Reply With Quote
Old 10-17-2007, 04:35 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 700
Thanks: 2
Salathe is on a distinguished road
Default

False. The constants are defined and only available at runtime, not across different page loads.
__________________
Salathe is offline  
Reply With Quote
Old 10-17-2007, 04:49 PM   #7 (permalink)
The Gregarious
Upcoming Programmer Inquisitive 
 
Join Date: Sep 2007
Posts: 650
Thanks: 82
Tanax is on a distinguished road
Default

okey, thanks! :D
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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


All times are GMT. The time now is 12:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0