Auto Append to only PHP Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Auto Append to only PHP Files

Post by tecktalkcm0391 »

How can I set PHP to only append .php files? I dont have access to php.ini, only .htaccess :(
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

only append what? :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If auto append is set it will append to all files that php processes. If you can access the auto append file you can use the various variables available to determine if you are in a PHP file or not.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Oh ok, cause I have some .JS files with PHP on them, so I need to do something. Well I tried using __FILE__ and basename, then getting the .__ but it ran no matter if it was or wasn't .php...

Any suggestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What did you do for debugging?
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

I included filetype.php on the header.php page. You can see below:
header.php wrote:

Code: Select all

<?php
require_once("filetype.php");
if(isset($allow_p35TraNE) && ($allow_p35TraNE==1)){
          require_once("header_add.php");
}
?>
filetype.php wrote:

Code: Select all

<?php
// Allow Extentions: 
$allowed_p35TraNE = array(".php",".htm",".html");

$file_type_s4EphAde = __FILE__;
$file_type_s4EphAde = basename($file_type_s4EphAde);
$file_type_s4EphAde = strtolower(strrchr($file_type_s4EphAde, '.'));

if(in_array($file_type_s4EphAde, $allowed_p35TraNE)){
	$allow_p35TraNE = 1;
} else {
	$allow_p35TraNE = 0;
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not seeing any debugging. Did I miss something?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

__FILE__ returns the name of the current file, even if it's an include file. It will always be the name of the file you're appending. Check for things in $_SERVER ;)
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Thanks. $_SERVER['SCRIPT_FILENAME'] worked :)
Post Reply