Category : "Tutorial"

Php web development tutorials

40+ Useful Php tips for beginners – Part 1

In this series we are going to look into some useful tips and techniques that can be used to improve and optimise your php code. Note that these php tips are meant for beginners and not those who are already using mvc frameworks etc. The Techniques 1. Do not use relative paths , instead define a ROOT path Its quite common to see ...

Php get list of locales installed on system

On linux , the list of locales installed on the system can be fetched through the terminal command locale -a : $ locale -a C C.UTF-8 en_AG en_AG.utf8 en_AU.utf8 en_BW.utf8 en_CA.utf8 en_DK.utf8 en_GB.utf8 en_HK.utf8 en_IE.utf8 en_IN en_IN.utf8 en_NG en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 en_ZA.utf8 en_ZM en_ZM.utf8 en_ZW.utf8 es_AR.utf8 es_BO.utf8 es_CL.utf8 es_CO.utf8 es_CR.utf8 es_DO.utf8 es_EC.utf8 es_ES.utf8 es_GT.utf8 es_HN.utf8 es_MX.utf8 es_NI.utf8 es_PA.utf8 es_PE.utf8 es_PR.utf8 es_PY.utf8 es_SV.utf8 es_US.utf8 es_UY.utf8 es_VE.utf8 hi_IN hi_IN.utf8 nl_AW nl_AW.utf8 nl_BE.utf8 nl_NL.utf8 POSIX si_LK si_LK.utf8 zh_CN.utf8 zh_SG.utf8 Now this command can be used inside php to get the list. Along with this list we can also add some information like language name and country name using a list of countries and languages. Here is a list ...

Php script to fetch whois information of ip address

Whois information of ip addresses IP addresses are in the form of a.a.a.a where each letter is a number from 0-255. You would be happy to know that every ip address has some information associated to it. For example which isp or organisation has been allotted that ip address and where is that organisation located. This in turn tells the location ...

Disqus Comments Importer Script in PHP

Disqus is a great commenting platform that does it's job really well. Many people use it these days because writing your own commenting system is a tedious and hard work whereas a solution like Disqus or Livefyre makes the entire commenting process a breeze with features like social logins, many levels of nesting, easy replying, quick and realtime commenting, easy ...

Php : create pdf from html using mpdf

MPDF Many php applications need to create pdf of documents like invoice , receipt and even id card etc. In this article we shall create a pdf invoice using the mpdf pdf creation library. Mpdf is made in php without any other external library. Mpdf parses css much better than any other free pdf libraries like tcpdf and creates pdf files ...

Php get zip error message from error number

Php functions like zip_open return an error number if they fail. To get the corresponding error message from the error number , use the following function. function zip_error_message($errno) { // using constant name as a string to make this function PHP4 compatible $zipFileFunctionsErrors = array( 'ZIPARCHIVE::ER_MULTIDISK' => 'Multi-disk zip archives not supported.', 'ZIPARCHIVE::ER_RENAME' => 'Renaming temporary file failed.', 'ZIPARCHIVE::ER_CLOSE' => 'Closing zip archive failed', 'ZIPARCHIVE::ER_SEEK' => ...

Get http request headers in php

When a browser makes a request to a php script, the browser sends some http headers which can look like this : Host: localhost Connection: keep-alive User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: UTF-8,*;q=0.5 Cookie: username=admin; password=21232ffc3; PHPSESSID=o5m4e2td1m66c4pkjdag9vs0u2 The php script under request , may want to access these http headers. PHP has a method getallheaders() which provides ...

Parse MVC style urls in PHP

If you have used codeigniter or some mvc php framework then you might be aware of urls like www.yoursite.com/index.php/class/method/param1/param2?a=b&c=d or www.yoursite.com/class/method/param1/param2?a=b&c=d if you use mod rewrite to add the index.php The htaccess code could be like this : <IfModule mod_rewrite.c> #Start the rewrite engine RewriteEngine on #If requested thing is not a file or directory , then rewrite RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ...

Suppress Errors & Warnings With @ operator in PHP

The at sign (@) is an error control operator in PHP. You can suppress errors, warnings and notices using @ operator in PHP. It is quite common to prefix function calls with @ to suppress errors like this - <?php @mysqli_connect($host, $user, $pass, $db_name); # If the connection is not established for some reason, then the error will be suppressed @getimagesize('lol.png'); # If ...

Write a simple PHP Hit Counter Script

In this tutorial, I am going to show you a simple way to write a Hit Counter script in PHP to save and display the number of visits to your website. We will basically store and increment the hits in a file, that can be used to display the total hit count as well. The code to store the hits follows - <?php class ...

Pages:«123456»


Connect with us