Thursday, June 21, 2012

How to increase PHPs execution time for processing large set of records?

1. In php.ini file change the below line values it will change the maximum execution time.

max_execution_time 30

2. To increase the execution time runtime we can use the ini_set() function.
e.g.
ini_set('max_execution_time' '-1'); - it sets maximum execution time to infinity.

What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart.

To prevent spammers from using bots to automatically fill out forms, CAPTCHA code generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans can determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field the application can be fairly assured that there is a human client using it.

What are the different methods to optimize the MySQL query?

It does not depend upon single entity. In order to optimize you have to consider many things:

1. Make sure table has primary key.

2. If there is any field which is used more frequently for searching then INDEX it.

3. Check the order of join condition.

4. In "Select" statement "where" condition should have indexed column.

5. Use "Limit" clause to fetch required amount of records from the database.

6. Use "count()" instead of "*" if you want to know the number of records fetched from the DB.

How to prevent form Hijacking in PHP?

Following the below steps can help prevent your PHP Form from getting Hijacked:

1. Make "register_globals" set to "Off" to prevent Form Injection with malicious data.

2. Make "Error_reporting" set to "E_ALL" so that all variables will be initialized before being used.

3. Make practice of using htmlentities(), strip_tags() and addslashes() to filter out malicious data entered.

4. Make practice of using mysql_escape_string() in mysql.

5. User Input Sanitization: Never trust web user submitted data. Follow good client side data validation practices with regular expressions before submitting data to the server.

Store Image in MySQL

We can use the "blob" datatype for storing the the image into the table.

However, the best way to store images into MySQL is to store the location of the image as a character string.