Protect Your PHP File From Direct Call

13 Oct

Sometime you might face a saturation with you do not want a user to browser/call your PHP file.  In that case obviously you need some kind of protection.  Just use this below code to protect your PHP file from direct call.  Put this at the top of your PHP file which you would like it to be protected from direct call/browse.

 if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
 

Tags: ,

Validate Phone Number

13 Oct

This below code will help you to validate phone number. (e.g. from form submit).

### Validate country code, area code and phone number

 $intisd=$_POST["txtcountrycode"];
 $intccode=$_POST["txtareacode"];
 $intphone=$_POST["txtphone"];

if(substr_count($intisd,"+")>0){
 if(strpos($intisd,"+")==0)
 $intisd=substr($intisd,1,strlen($intisd));
 }

if($intisd != NULL){
 $result=ereg("^[0-9]+$",$intisd,$trashed);
 $result=ereg("^[0-9]+$",$intisd,$trashed);
 if(!($result)){$errors[] = "Please enter valid country code.";}
 }
 if($intccode != NULL){
 $result=ereg("^[0-9]+$",$intccode,$trashed);
 if(!($result)){$errors[] .= "Please enter valid area code.";}
 }
 if($intphone != NULL){
 $result=ereg("^[0-9]+$",$intphone,$trashed);
 if(!($result)){$errors[] .= "Please enter valid phone number.";}
 }
 

Tags: , ,

[WordPress] How To Publish A WordPress Plugin

15 Jul

Today, I found a nice blog post about how to publish a WordPress plugin on the net.  So I’ve decided to share it on my blog.  It helped me a lot and shown me the clear picture of how SVN work and what are the procedures to publish a plugin to the WordPress repository.  Click here to read the full details.

Cheers! :)

Tags: , , , , , , ,

How To Add Google +1 Button To Your Site

7 Jul

I am not going to write a long post for this.  It can be done by writing two lines of code.  Just go to this page .  All the information are listed there.

Cheers! :)

Tags: , , , ,

WP Voting Plugin

27 Jun

Description
Site owner to add voting functionality to the blog posts.

Features
1. Control voting feature via voting on/off
2. Control allow or disallow post author to vote his own posts
3. Customise vote and voted text
4. Customise vote and voted buttons images
5. Customise alert message for non logged in users
6. Voting logs for site administrator
7. Sort voting logs by vote count or voted date
8. Show current vote count and vote button on frontend templates
9. Compitible with almost all of the themes. You just need to call required function from your template
10. Now shortcode supported
11. Total vote count widget
12. Now public voting supported
Continue reading 

Tags: , , , , ,

Javascript Form Reset And Cancel

27 Jun

When you are working with html form, you might need this below javascript code to implement form reset and cancel features.

 <script type="text/javascript">
 function clearform(){
 if(confirm("Are you sure you want to reset the form?")){
 document.res_reg.reset();
 }
 }

function cancelAction() {
 var cancel=confirm("Are you sure you want to cancel?")
 if (cancel==true)
 {
 // Go back (Same result as pressing browser back button)
 history.go(-1);
 }
 else
 {
 <!-- nothing happens-->
 }
 }
 </script>
 

 <input type="button" value="Reset" onclick="clearform();return false" />
 <input type="button" value="Cancel" onclick="cancelAction();" />
 

Tags: , , , ,

JQuery HTML Option Selected Index Change

27 Jun

This is not new but I would like it to be posted on my site. So here is the jQuery code to trigger the event when user selects the HTML option box.

<script type="text/javascript">
jQuery(document).ready(function($){
 $("#yourOptionID").change(function (){
 var selVal = $("#yourOptionID").val();
 if(selVal != null){
 //Add your code
 }
 else {
 //Add your code
 }
 });
 });
 </script>

Tags: , ,

Follow

Get every new post delivered to your Inbox.