Blog Archives


As a website designer, when we are designing our website, we should know whether people are using mobile ,pad or pc to visit our website, then our website can display them different scale page, mobile is small, pad is media and at last display big page in pc.

To answer this question we can use php, if your website is built by php, you can do like these two steps.

Step 1: Create a php function to check visitor are using mobile

To create a php function which can tell you whether visitors are using mobile or not, you can use code below:


function is_mobile_request()
{
 $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
 $mobile_browser = '0';
 if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
 $mobile_browser++;
 if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
 $mobile_browser++;
 if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
 $mobile_browser++;
 if(isset($_SERVER['HTTP_PROFILE']))
 $mobile_browser++;
 $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
 $mobile_agents = array(
 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
 'wapr','webc','winw','winw','xda','xda-'
 );
 if(in_array($mobile_ua, $mobile_agents))
 $mobile_browser++;
 if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
 $mobile_browser++;
 // Pre-final check to reset everything if the user is on Windows
 if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
 $mobile_browser=0;
 // But WP7 is also Windows, with a slightly different characteristic
 if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
 $mobile_browser++;
 if($mobile_browser>0)
 return true;
 else
 return false;
}

2 Steps to use http referer in php


Recently, When i see the traffic number of my blog, i notice most of visitors come form other website. Google Analytics shows what they are,as picture below shows.

php link reference

By Google Analytics, i find most of visitors of my sites are from linkreferral.com, once i find it, i have a question:How to know google analytics know where these visitor come from?

I have search some papers by google and know it is that http referer helps google analytics to know where these visitors are from.

Step 1: What is http referer

I think http referer is a link, which means if you visit my blog by click a google search result, the information ‘google.com’ will be stored up in http referer, then my website or other website statistics tool,like google analytics, will know where you are from.


Nowadays,QR code is used widely,we can see it almost everywhere, cell app, advertisements and some news websites. It is a type of tow-dimensional barcode and provide a new and fashion way to get new message for us. if you plan to add it to your website, your advertisement or video, you may wonder how to create it and today we introduce  to use php and google api to create one.

Step 1: Check some useful information before creating a qr code

qr code is a carrier of message and massage it can carry is limited, 4,296 alphanumeric characters is its toplimit. So if you plan to use a qr code to store up your information, you must be sure the length of your information is not longer than 4,296.

Category: PHP Programming

TAG


In article 2 Steps to convert png into ico file , i introduce steps to convert a png image into a ico, In that article, we use some online tools to do it.However, if you want to do it by php and plan to build a website to supply service of converting png to ico. I think you can read this post.

To convert png into ico file by php script, you use phpthumb to help us to do it, you can do as follow steps.

Step 1: Download phpthumb

You can click phpThumb to open page to download it, to realize function of converting png into ico, you should download these file:

phpthumb.ico.php

phpthumb.functions.php

Tips and Warnings:

1. If you can not download these two files, you can email me or leave your comment, i will send to you

2.To use phpthumb, you should make your php gd library enable, you can read article “2 Steps to make PHP GD library enable”  to enable it.

2 Steps to make PHP GD library enable


If you plan to use php to process some images, you should make PHP GD library enable, to make it enable you can do like this.

Step 1: Check it enable?

You can create a php file and paste code below, then open it by your browser.


<?php

phpinfo();

?>

If you find result like below, you can be sure PHP GD library enable has been enable in your php develope evironment, and you can use it to process some images. If not, you can read step 2.

php gd library


To run php script by command line in window system, first of thing you should concern is php script can run at you computer system, if php script can not run at you computer, you can see this article 4 Steps to run php script in your computer.

If php script can run at you computer, you can view steps follow.

Step 1: Find php.exe path

If you install php.exe by appserv, you can find php.exe path, for example this path is called:F:\PHP\server\php-5.3.5

4 Steps to run php script in your computer


If you plan to study php programming, you may want to know how to run php script in computer, if you say this, you can realize by follow steps:

Step 1:  Download appserv

Appserv logo

You can download this software at Appserv download,after you downloaded, you can view step 2.