Php-PHP source code

Source: Internet
Author: User
For work, we need to write a computer mobile phone to share a domain name. When a mobile phone user accesses the mobile phone page, if a computer user accesses the web page, next we will find the php code for mobile users to share with you. For work, we need to write a computer mobile phone to share a domain name. When a mobile phone user accesses the mobile phone page, if a computer user accesses the web page, next we will find the php code for mobile users to share with you.

Script ec (2); script

Found online

The principle of mobile phone access is that the mobile phone is accessed through the proxy server of the mobile company. Then we can understand that a common computer uses a proxy server. When a mobile phone is accessed through a proxy server, the http header will undoubtedly contain a message:. This information provides valuable judgment information.
For example, the via information obtained by Henan mobile is:

Http/1.1 hazz-b-gw001-wap (infox-wisg, huawei technologies)
Henan Unicom's via information is:

Zxwap gateway, zte technologies

Code

The Code is as follows:

// Check if wap by xhatfunction
Check_wap (){
Return stristr ($ _ SERVER ['HTTP _ vean'], "wap ")? True: false;
}

The result is that no one can forge a mobile phone to access the website, and the judgment is absolutely accurate. Naturally, this protects the mobile phone wap simulators that are popular on the Internet-fundamentally.
This is definitely not the case.

This is the same on the Internet.

Php determines the function of the mobile browser. The Code is as follows. The judgment on ipad and android is added.

The Code is as follows:

// Check if wap
Function check_wap (){
If (stristr ($ _ SERVER ['HTTP _ pass'], "wap") {// check whether the proxy is a wap proxy, Which is accurate.
Return true;
} Elseif (strpos (strtoupper ($ _ SERVER ['HTTP _ ACCEPT ']), "VND. WAP. WML")> 0) {// check whether the browser accepts WML.
Return true;
} Elseif (preg_match ('/(blackberry | configuration/cldc | hp-| htc _ | htc-| iemobile | kindle | midp | mmp | motorola | mobile | nokia | opera mini | opera | Googlebot-Mobile | YahooSeeker/M1A1-R2D2 | android | iphone | ipod | mobi | palm | palmos | pocket | portalmmm | ppc; | smartphone | sonyericsson | sqh | spv | symbian | treo | up. browser | up. link | vodafone | windows ce | xda _)/I ', $ _ SERVER ['HTTP _ USER_AGENT']) {// check USER_AGENT
Return true;
} Else {
Return false;
}

}

There is still a problem after the test. If you do not know it, you can see the wordpress function. php file.

The Code is as follows:

// Determine whether the mobile phone belongs
Function is_mobile (){
$ User_agent = $ _ SERVER ['HTTP _ USER_AGENT '];
$ Mobile_agents = Array ("240x320", "acer", "ACO on", "acs-", "abacho", "ahong", "airness", "alcatel ", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic ", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm -", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly _", "fly-", "go. web "," goodaccess "," gradiente "," grundig "," haier "," hedy "," hitachi "," htc "," huawei "," huchison ", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge -", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm ", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser ", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips ", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem ", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh -", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian ", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshba", "tsm ", "up. browser "," utec "," utstar "," verykool "," virgin "," vk-"," voda "," voxtel "," vx "," wap ", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte ");
$ Is_mobile = false;
Foreach ($ mobile_agents as $ device ){
If (stristr ($ user_agent, $ device )){
$ Is_mobile = true;
Break;
}
}
Return $ is_mobile;
}

Add on your web

The Code is as follows:

If (is_mobile ()){
Include ('Access The. php file via the cell phone '); exit;
}

There are many ways to solve such problems. If you don't want to do this, you can directly use the second-level domain name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.