thephpcode is where your PHP resources flow and you can find tips and tricks of PHP coding. Code snippets and examples are also provided. Best of PHP are included in thephpcode. Remember, if you have questions, do post a comment on the relevant post.

Sunday, July 5, 2009

Sometimes you just want the files to be included, but not called directly. you might want to do this for security or what other reasons. here's the simple code:

<?php

if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}

?>

if name of the file requested is the same as the current file, the script will exit directly. place this at the top of the scripts you want to set include-only.

However, take note that if the name of your included file is the same as your main file, it will get kicked out as well. As a developer, the convention is to name your files differently. e.g. users.php and users.inc.php

2 comments:

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end. PHP Training in Chennai

Start Overflowing

Buy author coffee!

Write In/Requests

hello all! thank you for visiting thephpcode - where php codes are shared and explained. I really hope you like the every little tips and tricks i write in just for you.

In order to keep this going, I'd really love to hear from you. If you have any compliments or feedback write them to hellclanner at gmail dot com. OR if you have any requests for tutorials or walkthroughs for PHP codes, HTML, CSS, Javascript - do write them in.

Sponsored

thephpcode choice php help and guide website/blog that allows php developers to rapidly develop their applications with the use of guides from thephpcode. choice functions and hot news about php are all here. we also have code examples shown to help you understand php better. also we include portions of mysql, apache and other technologies that you might need on your php journey. cool huh?