Saturday , November 23 2024

Tag Archives: PHP

Parse JSON Data Using PHP

With most of the popular web services like Twitter providing their data through APIs, it is always helpful to know how to parse API data which is sent in various formats including JSON, XML etc. 

Read More »

Generate An Authentication Code in PHP

This basic snippet will create a random authentication code, or just a random string. <?php # This particular code will generate a random string # that is 25 charicters long 25 comes from the number # that is in the for loop $string = “abcdefghijklmnopqrstuvwxyz0123456789”; for($i=0;$i<25;$i++){ $pos = rand(0,36); $str …

Read More »

Encode Email Address using php

With this snippet, you can encode any email address into HTML entities so that spam bots do not find it. function encode_email($email=’info@domain.com’, $linkText=’Contact Us’, $attrs =’class=”emailencoder”‘ ) { // remplazar aroba y puntos $email = str_replace(‘@’, ‘@’, $email); $email = str_replace(‘.’, ‘.’, $email); $email = str_split($email, 5); $linkText = str_replace(‘@’, …

Read More »

Validate Email Address

Sometimes, while filling forms on your website, a user can mistype his email address. Using the below function you can check if the email provided by user is in correct format.

Read More »

DETECT LOCATION OF THE USER

Using the below function you can check the city from which the user is visiting your website. function detect_city($ip) { $default = ‘UNKNOWN’; $curlopt_useragent = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)’; $url = ‘http://ipinfodb.com/ip_locator.php?ip=’ . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION …

Read More »