Web Hosting

The Web Hosting Community

Advanced search
  • HOME
  • TOP HOSTING
  • TOOLS
  • FORUM
  • WIKI
  • NEWS
  • English
  • Spanish
  • Hebrew
  • Forum ‹ Main Forum ‹ Programming Discussion ‹ PHP
  • Change font size
  • Print view
  • FAQ
  • Register
  • Login

How to redirect by language with php

All about php scripting. Questions, advices and anything about php programing.
Post a reply
2 posts • Page 1 of 1

How to redirect by language with php

Postby tim on Wed Aug 13, 2008 10:27 pm

hi all,
anyone knows how to redirect a user by the language set on the web browser?
help wiil be appriciated,
tim
tim
 
Posts: 8
Joined: Sun May 11, 2008 8:05 am
Top

Re: How to redirect by language with php

Postby talshk on Thu Aug 14, 2008 11:58 am

hi tim,
try using the following code and see if it helps.
the code is basicly a class for manipulating languages in php.
feel free to edit and use this code:
Code: Select all
<?php
class lang {
/**
* @author tal shkolnik
* @Website: www.hostpedia.org
* @copyright 2008
*/

var $code = null;
var $langs = array('en' =>"English",'es'=>"Spanish",'fr'=>"French",'zh'=>"Chinese");
   
   function __construct($lang = ''){
      $this->code = $this->auto_lang($lang);
      $this->load_lang_tags();
   }

   public function is_language($lang = 'en'){
      return array_key_exists($lang, $this->langs);
   }

   private function browser_lang(){
      $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
      $lang = (isset($lang) && $lang != "") ? $lang : "en"; //handles empty values by spiders
      return ($this->is_language($lang)) ? $lang : 'en';
   }
   
   public function auto_lang($lang=''){
      if ((empty($lang)) || !($this->is_language($lang))){
         $code = $this->browser_lang();
         $code = (isset($code))? $code : "en";
      } else {
         $code = $lang;
      }
      return $code;
   }
   
   public function get_code(){
      return $this->code;
      }
   
}

?>
talshk
Site Admin
 
Posts: 10
Joined: Sun May 04, 2008 11:06 am
Top


Post a reply
2 posts • Page 1 of 1

Return to PHP

Who is online

Users browsing this forum: No registered users and 0 guests

  • About Us
  • Privacy
  • Terms & Conditions
  • Web Host Login
  • List Your Web Host
  • Contact us
Copyright © 2007 HostPedia.org Web Hosting, All rights reserved, Forum powered by phpBB.
cron