Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

hide your templates with php

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
carsten888
Smarty Rookie


Joined: 26 Feb 2005
Posts: 13
Location: Tilburg, Holland

PostPosted: Tue Dec 13, 2005 7:12 pm    Post subject: hide your templates with php Reply with quote

(something like this has been posted here before, but can't find it anymore. this is a refinement of that code)

to prevent search-engines and viewings from browsers in your templates, put this code above the <html>-tag and save it as a php file:

{if $youAreTryingToLookAtMyTemplate == true}
<?php buggerOff(); ?>
{/if}
<html>

if the template is properly called for by php the smarty will read the code, conclude that crazy variable does not exist and happily go on.
if someone requests the page(.php) from a broser, the smarty is not read but the php is. this will trow an error because the function buggerOff() is unknown.

a nice bonus is that this code will not mess up code-colors in Dreamweaver.
Back to top
View user's profile Send private message Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Wed Dec 14, 2005 1:48 pm    Post subject: Reply with quote

put your templates outside of your document_root and you won`t have any Problems.
Back to top
View user's profile Send private message
Milkman
Smarty Regular


Joined: 21 Nov 2005
Posts: 57
Location: Loughborough, UK

PostPosted: Thu Dec 15, 2005 3:00 am    Post subject: Reply with quote

carsten888 wrote:
to prevent search-engines and viewings from browsers in your templates, put this code above the <html>-tag and save it as a php file:


Surely if you are using a file extention that does not map to a mime-type of application/x-httpd-php this will not help? If you cannot put your templates outside of the document root (as kills suggests) perhaps you could add an apache RewriteRule (or similar which ever httpd you use) to send a 403 when someone requests a template file. Putting the following in a .htaccess file would do the trick (replace .tpl with your template extension).

Code:
RewriteEngine on

RewriteCond %{REQUEST_URI} \.tpl$
RewriteRule .* - [F]



Edit: I've just re-read your post and I now see that you use .php as your template extension. Rolling Eyes
Back to top
View user's profile Send private message Visit poster's website
avataru
Smarty Rookie


Joined: 09 Jan 2006
Posts: 7

PostPosted: Sat Jan 14, 2006 11:21 am    Post subject: Reply with quote

In most places mod_rewrite is not available but there is another way to do it from .htaccess.

Make a .htaccess file and put it in the root dir. Then, add this:

<Files *.tpl>
order allow,deny
deny from all
</Files>
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP