Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, 17 July 2012

Read GPS data from Photographs using PHP

Modern cameras equipped with GPS receivers add the GPS coordinates to every photographs it takes. Using this data, the exact location where the photograph was taken can be determined. This information can be very useful when archiving or organizing the photographs. The GPS data will be embedded in the photo along with the EXIF header. In this post I will show you how to extract this information and convert it to some meaningful data using PHP.

Wednesday, 11 July 2012

Maximum execution time exceeded - Error in PHP

You might have come across a Fatal error stating Maximum execution time of 30 seconds exceeded when running time consuming PHP scripts. Well, PHP sets its default maximum execution time for a script to 30 seconds so that the server is not overloaded running long scripts. But there are times when you need to run some time consuming scripts that does some database maintenance or processing large amounts of data. In such cases you are likely to exceed the 30 seconds time limit. PHP has a built in function set_time_limit which can be used to change the maximum execution time.

Wednesday, 16 May 2012

Import CSV file to a Database using PHP

A CSV file, as the name suggests, contains a list of values separated by comma. The end of each row is marked by a line break. This is one of the oldest file format used in computers and hence is supported in almost all operating systems. In this post, I will describe how to use a CSV file to populate a MySQL database.

Check if Remote File Exists using PHP

You can easily check if a file exists using the PHP function file_exists(), but this function is limited to files within the same server. It will not work if you specify a location on a different domain. In that case you might want to use functions like file_get_contents(). Using these functions will download the whole file just to make sure that the file exists. This will take time and consume more memory. But this might not be what you want. You might just want to check if the file exists and not download it. In this post I have included a function with which you can do exactly the same.

INSERT IGNORE in MySQL

When you try to insert a new record in MySQL and the primary key specified in the insert query already exists, then an error will occur and the query will be aborted. Using the "IGNORE" keyword prevents errors from occurring. The records containing duplicate primary keys are ignored and the rest of the records are added. In the former case, no record will be inserted if such an error occurs.

Tuesday, 15 May 2012

Use PHP with MySQL

The main reason for many web developers to learn a scripting language like PHP is because of the ease with which it can interact with databases. In this post I will show you how to use PHP and the MySQL database to store information on the web and include it into your website. Before you read this tutorial you should have at least a basic knowledge of how to use PHP.

Introduction to AJAX

AJAX stands for Asynchronous JavaScript And XML and is a technique used by web developers to make their web sites fast and dynamic. The advantage of using AJAX is that you can update a part of your webpage without reloading the whole page. That is you can send and receive data to and from a server without refreshing  the page. This enables you to minimize data transfer and hence improve performance. Now in this post, lets see how to start using AJAX on your web application.

Wednesday, 9 May 2012

Create JSON from MySQL To use with AJAX

Now a days most websites use the power of AJAX to make their website more lively and productive. To transfer large amount of raw data, that JavaScript can process, the best way is to transfer it as a JSON file. It is quite easy for a PHP script to generate a JSON file from raw data. This data can be received using a suitable AJAX call. As JavaScript can easy parse JSON object, the rest of the processing with the received data can be done using JavaScript.

Thursday, 3 May 2012

Make a case sensitive MySQL Search

You might have noticed that when you search for a string in MySQL using '=' or 'LIKE' keyword, the search is not case sensitive. That is you will receive all records irrespective of the case (Uppercase or Lowercase). This is advantageous in several cases, but there are situations when you want the search to be case sensitive.

Get the details of an image in PHP

Every image file has a header section in it which describes the size of the image, its type and other parameters. This header can be used to retrieve the image details. It can be helpful in a PHP program either to validate the file type or to prepare the image for output. This function can be used to find the actual file type (GIF, JPEG...) eventhough the file extention provided is different or is not provided. This function can be used along with file upload scripts so that the actual file type can be verified.

Saturday, 28 April 2012

Guide to Good Programming Habits

From a novice programmer to a veteran, there are a few rules to be followed so that the code you write has a professionalism in it. These might be simple things like adding comments or using proper variable names, but following it in a systematic way will make your code more easy to develop, test, debug and deploy. These rules are applicable to any programming language and making it a habit will help you in the long run. In this post, I will explain a few rules that could be followed.

Monday, 16 April 2012

Database - Primary Key And Foreign Key

The primary key of a table uniquely identifies each row in a table. In a table, only one field can be assigned as a primary key. The primary key will be guaranteed as unique in the entire table, that is no two rows in a table will have the same primary key. The foreign key field of a table is used to match the primary key field of another table.

Friday, 13 April 2012

Random String Generator in PHP

There are many occasions where you might require a random string in your application. It may be used for generating a key for an encryption algorithm or just to supply a random password to a user. Here a simple PHP function gen_rand_str() is given which can meet these requirements.

Thursday, 12 April 2012

Validation - Client or Server Side

Whenever data is transferred from a client to the server, it is extremely important to validate the data so as to ensure the secure and successful completion of the process. The question lies with whether the validation has to be done in the server alone or in both server and client side. Which one will be the better and efficient choice. Obviously validation in the client side alone is not at all an option because it can be easily bypassed.