[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

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
0
global_expert_advice
Asked:
global_expert_advice
  • 5
  • 2
  • 2
  • +1
1 Solution
 
Julian MatzCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 MatzCommented:
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 MatzCommented:
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 MatzCommented:
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
 
global_expert_adviceAuthor Commented:
Thanks for the help.. it solved my problem
0
 
Julian MatzCommented:
Gald I could help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now