checking if .tpl file is included or not in page using php smarty

ok i have an issue.
i m having a abc.tpl file which includes
header.tpl
body.tpl
footer.tpl
Now what i want is when we load abc.php which displays abc.tpl
it should check whether footer.tpl is included or not, if not the page should redirect to xyz.php
even if any one alters or modify footer.tpl to footer1.tpl or even removes page should redirect.

Can anyone put some idea here how to do this,
thanks in advance
LVL 1
global_expert_adviceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian M.Web DeveloperCommented:
How about encrypting the abc.tpl and footer.tpl files with IonCube Encoder? That way, it would be impossible for anyone to modify them.
0
re-searcherCommented:
.tpl file usually used for template files and in normal state you should using template engines.
i want to say some examples here which will help you for creating best and optimized php site with PHP.

in this example i will describe with Smarty.

* please, download smarty from -> http://www.smarty.net 
* learn smarty template engine's syntax. (actually it's very simple). -> http://www.smarty.net/documentation
* paste smarty template engine in you php script directory
* declare and call smarty classes which "how to" should be available in document.
* use {include} command for calling tpl files.
* paste all tpl files to smarty template directory
* check permissions, cache and some other folders should be writable (chmod 777). it's available on documents,too.
* load abc.tpl with following code in your abc.php:
$smarty->display('abc.tpl');

Open in new window


if you agree with my solution and need more information let me now.
or if you're/wanna using other template engines tell here i will say what you should do exactly.
0
Ray PaseurCommented:
I am trying to understand the question.  Are you actually giving your PHP code to a third party and expecting them not to modify it?  If that is the case, you really should go with something like IONCube.  If you want to know whether or not a script is included, see example 4 on this page.
http://us3.php.net/manual/en/function.include.php
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

global_expert_adviceAuthor Commented:
hi
i m well aware of smarty and using the same for building our software.
We are giving the software to end users, but restricting them not to change the powered by link in footer.
We have footer.tpl... okay if we encode it using ioncube...which i already used to encode rest of the php files. what if the end user rename footer.tpl to footer1.tpl or delete it and create a new footer.tpl.

as all the pages are using footer.tpl....
so my question was like user should not be able to remove the include footer.tpl file from any page if removed give some error....
0
Ray PaseurCommented:
Suggest you either use IONCube or set up a monitor to read the end users' implementations of the web site.  You can use file_get_contents() or CURL to read the generated HTML from the end users' sites.  If you find that the footer text goes missing you can flag the site for legal intervention.
0
Julian M.Web DeveloperCommented:
I've thought about this for a while, and I'm pretty sure I have a solution. Just give me a few moments to test it.
0
Julian M.Web DeveloperCommented:
Yes, this will definitely work. Let's say your index.php file looks something like this:

<?php
session_start(); // Starts your sessions
ob_start(); // Turn on output buffering
require_once( 'includes/init.php' ); // This loads your configs, classes, functions, etc.
$smarty->display( $content ); // Displays your Smarty template
ob_end_clean(); // Send the output buffer
?>

Open in new window


You could add the following to the very beginning of your encrypted footer.tpl file:

{php}$this->key = 'abc123';{/php}

Open in new window


You can choose whatever string / passphrase you like. You then add the following to the very end of your encoded index.php file:

$key = 'abc123' // Enter the same passphrase as above;
if ( !isset( $smarty->key ) || $smarty-key !== $key )
{
     ob_end_clean(); // Erase output buffer to prevent previous output
     die( "Error: violation of terms! Please put back the original footer.tpl file." );
}

Open in new window


Now, no one can run your app unless they either have the correct footer.tpl in place or they know your key / passphrase. You could now even generate a key or license file and charge an additional fee to have the powered-by footer removed. If the fee is paid, you could simply give them the key, which they could enter into some config file. Then, they'd be able to use whatever footer they like. (Just a suggestion).

Your full index.php file would now look something like this:
<?php

session_start(); // Starts your sessions

ob_start(); // Turn on output buffering

require_once( 'includes/init.php' ); // This loads your configs, classes, functions, etc.

$smarty->display( $content ); // Displays your Smarty template

$key = 'abc123' // Enter the same passphrase as above;
if ( !isset( $smarty->key ) || $smarty-key !== $key )
{
     ob_end_clean(); // Erase output buffer to prevent previous output
     die( "Error: violation of terms! Please put back the original footer.tpl file." );
}

ob_end_clean(); // Send the output buffer

?>

Open in new window


Hope that helps.
0
Julian M.Web DeveloperCommented:
Or this might be an even more elegant way to do it:

index.php:
<?php

session_start(); // Starts your sessions

ob_start(); // Turn on output buffering

require_once( 'includes/init.php' ); // This loads your configs, classes, functions, etc.

$smarty->display( $content ); // Displays your Smarty template

$key = 'abc123' // Enter the same passphrase as above;
if ( !isset( $smarty->key ) || $smarty-key !== $key )
{
     ob_end_clean(); // Erase output buffer to prevent previous output
     die( "Error: violation of terms! Please put back the original footer.tpl file." );
}

ob_end_clean(); // Send the output buffer

?>

Open in new window


footer.tpl
{* IMPORTANT: Please do not remove this line! *}
{php}include( 'license.php' );{/php}
{* Rest of your footer.tpl below... *}

Open in new window


license.php
<?php $this->key='abc123'; ?>

Open in new window


That way, your users still have control over the footer.tpl file, but will still be forced to display your powered-by section. They'd even be able to move the powered by link to. This will also work if you don't have the IonCube Encoder and if the online encoder cannot encrypt non-php files (not sure whether it does or not). Just be aware that you might need to implement some kind of CSS or JavaScript also to prevent users from hiding the powered-by section, using for example CSS "display: none;".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
global_expert_adviceAuthor Commented:
Thanks for the help.. it solved my problem
0
Julian M.Web DeveloperCommented:
Gald I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.