PHP implementation get and set User access page language class, PHP page _php tutorial

Source: Internet
Author: User

PHP implementation get and set User access page language class, PHP page


This article describes the implementation of PHP to get and set the user Access page language class, share to everyone for your reference. The specific analysis is as follows:

The instance user Language Class gets/sets the page language that the user accesses, and if the user does not set the access language, reads Accept-language. Display the corresponding page according to the language selected by the user (English, Simplified Chinese, Traditional Chinese)

The UserLang.class.php class file is as follows:

<?php/** user Language Class gets/sets the language of the page that users access, reads Accept-language * date:2014-05-26 * author:fdipzone * If the user does not have set access language ver:1.0 * Func: * Public get get user access language * Public set Set User access language * Private Getacceptlanguage get HTTP_ACC  Ept_language */Class userlang{//class start private $name = ' userlang ';//cookie name private $expire = 2592000; Cookie expire/** initialization * @param String $name cookie name * @param int $expire Cookie expire */PU     Blic function __construct ($name = ", $expire =null) {//Set cookie name if ($name! =") {$this->name = $name; }//Set cookie expire if (Is_numeric ($expire) && $expire >0) {$this->expire = intval ($expire     ); }}/** gets the user access language */Public function get () {//To determine if the user has set the language if (isset ($_cookie[$this->name])) {$lan     g = $_cookie[$this->name];     }else{$lang = $this->getacceptlanguage ();   } return $lang; }/** Set User access language * @paraM String $lang User Access language */Public function set ($lang = ') {$lang = Strtolower ($lang); can only be in English, Simplified Chinese, Traditional Chinese if (In_array ($lang, Array (' en ', ' SC ', ' TC ')) {Setcookie ($this->name, $lang, Time () + $this-&gt     ; expire); }}/** gets http_accept_language */Private Function Getacceptlanguage () {$lang = Strtolower ($_server[' HTTP_ACC      Ept_language ']);     if (In_array (substr ($lang, 0,5), Array (' ZH-TW ', ' Zh_hk '))) {$lang = ' TC ';     }elseif (In_array (substr ($lang, 0,5), Array (' ZH-CN ', ' ZH-SG ')) {$lang = ' SC ';     }else{$lang = ' en ';   } return $lang;  }}//class end?>

The Demo sample program is as follows:

<?php  require "UserLang.class.php";  $obj = new Userlang (' Sitelang ', 3600); echo $obj->get (). '
';?>

I hope this article will be helpful for you to learn PHP programming.


PHP How to implement restrictions on user access, such as a is the login page, B is to display the user Information page, how to let the user only through a to access B?

In the B page, you can determine the value of $_server[' Http_referer ' to get access from a, you can write the following code:
echo $_server[' Http_referer '];
if ($_server[' http_referer ']!= ' normal access to the contents shown above ') exit;

How to use PHP and HTML to access the database in the Web page and implement user login?

Say the main use of the function bar, the specific code, depends on your own requirements, but also a lot.

mysql_connect () This function is used to connect the MySQL database
mysql_query () This function is used to execute the SQL statement, the user logged in, here to query the database there is no user name and password and user input are the same record, there is a validation.
Mysql_fetch_array ()
HTML section:





</form>

Specifically, read the manual or look for an example.
 

http://www.bkjia.com/phpjc/883678.html www.bkjia.com true http://www.bkjia.com/phpjc/883678.html techarticle php implementation gets and sets the user Access page language class, PHP page This article describes the PHP implementation to get and set the user Access page language class, share to everyone for your reference. Specific analysis ...

  • 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.