Razer Megasoma Review

Razer Megasoma is a hybrid of a hard and a soft mouse mat; If you love the softness of a soft mat but want to have the speed of a hard mat, Razer Megasoma delivers (this is debatable and I guess more like a personal preference). Razer Megasoma sits somewhere in between, combining the best [...]

Blocking direct access to your PHP scripts in Joomla







by Michael Aulia on 14 June, 2008

in Blogging



I was scratching me head for a few days, trying to protect my stand alone PHP scripts for being accessed directly on the URL in a Joomla CMS system.

Googling here and there always referred me to the same htaccess codes, which didn’t work on my case for some reasons. So if you come here from the Search Engine, then you may want to try a slight modification to the htaccess codes that you have seen over and over again here.

Let’s say:

  • Your website domain is http://www.YOURDOMAIN.COM (and it’s in Joomla – I was using Joomla 1.5)
  • You have some individual PHP scripts under a folder called myscripts/
  • You are using the Joomla wrapper and wrap your PHP scripts nicely through the admin interface and only registered members can access the scripts.
  • However, if you type http://www.YOURDOMAIN.COM/myscript/myPHPscript.php on the browser, you find out that anyone can execute the script without registering/logging in to your Joomla System!

So the easy solution, is to put a [dot]htaccess (replace the [dot] with .) inside your myscript folder to block direct access to the folder or the scripts.

Your htaccess file should contain:

RewriteEngine On

# Blocking direct access
RewriteCond %{HTTP_REFERER} !^http://www.YOURDOMAIN.COM/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://YOURDOMAIN.COM/.*$ [NC]
RewriteCond %{REQUEST_URI} myscripts [NC]
RewriteRule .* – [F]

This will actually block any access if the URL contains …myscripts… This will work, because Joomla’s wrapper doesn’t tell you the directory name, but instead is using the Wrapper title that you specified on the Administration. So as long as you don’t put in the same name as the script folder, this will work.

Instructions:

  1. Replace your DOMAIN.COM with your real site’s URL.
  2. Replace myscripts with your own folder name
  3. Upload the htaccess file to your folder that you want to protect
  4. Test that going to the script using Joomla Wrapper’s URL works
  5. Test that typing straight on your browser to the PHP scripts gives you the Forbidden error message

Hope this helps.

Bookmark and Share



Subscribe Now

If you enjoyed this post, feel free to subscribe to be notified of new posts at Craving Tech!

{ 1 trackback }

Blocking direct access to your PHP scripts in Joomla
14 June, 2008 at 8:55 pm

{ 3 comments… read them below or add one }

Guy Vestal 15 June, 2008 at 3:18 am

I am not a Joomla user, but it is nice to see folks on top of security no matter the script or program. Great tip! Keep up the fight.

Dugg & Stumbled.

Guy Vestals last blog post..Entrecard Review & Favorite members

Reply to this comment

Nihar 16 June, 2008 at 7:22 pm

Michael,

I have seen joomla in my hosting service fantastico section. but never checked what it is? Let me check it…

Nihars last blog post..Use Virtual Audio Cable (VAC) to solve missing stereo-mix problem

Reply to this comment

Michael Aulia 16 June, 2008 at 11:13 pm

@Guy: Thanks for the Digg & Stumble!

@Nihar: It’s an open source CMS (Content Management System). So it’s something like Wordpress but bigger (not just for blogging, but for a full blown site complete with membership registrations, articles, forums, gallery, and everything that you can think of :) )

Reply to this comment

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled

Previous post:

Next post:



ss_blog_claim=90a03beb48f2cae080e36591e278f2e0