PHP Tutorials

Getting Visitor IP Address in PHP

Get Visitor IP Address

Some times we need to get visitor’s ip address for validation, security, spam prevention etc. In php it’s easy to get visitor ip address. No Proxy detection If there is no proxy detection we can get the visitor ip address with a simplest way as follow: But If a user access the website via a proxy server $_SERVER[‘REMOTE_ADDR’] will return the ip address of proxy server not of the proxy …

Continue reading

XML Parsing with SimpleXML

xml parsing with simplexml

XML Parsing basically means navigate XML document and provide the relevant data. Web services normally return data in XML format, you need to parse XML if you want to full use of APIs. In php 5.0 we have SimpleXML extension that provides a simple way to get XML element’s name and text. SimpleXML is fast and easy to use to read/extract data from XML strings. In this article I will …

Continue reading

How to create a zip file in php

How to create a zip file in php

In this post am going to explain, how to create a zip file in PHP of multiple files and force download the zip file. It is useful for some web projects, that providing the documents according to the selection of files like PDFs, images and docs etc and you can choose the files and download it in zip format. Here is a simple php code to create a zip file …

Continue reading

Zend custom controller helper

An action helper is a class that plugs into the controller to provide services to actions. They expand a controller’s functionality without using inheritance and so can be reused across multiple controllers and projects. To add Zend custom controller helper we can add it in library. Here I am creating a custom library for our purpose with the namespace ‘App’, so need to add it in application.ini to autoload these. …

Continue reading

Sort multidimensional array

To sort multidimensional array by values, you can use a user-defined comparison function usort. The function sort array by its values using a user-defined comparison function. If you want to sort an array by some non-trivial criteria, you should use this function. For example we have an array to sort: We need to sort this array according to the time in ascending order. So we need to use a user-defined …

Continue reading