网站语言选择 php

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:37:59
我准备使用html制作一个双语言(英文、中文),主页我想用php来做一个语言选择页,一下两种方式都可以:
1. 制作一个主页,让浏览者自己选择,然后使用cookie将语言保存下来
2. 自动语言选择页,浏览器设置是中文的,转到中文网站,其他的转到英文网站。

请不要浪费时间复制其他网站的东西了,不会的请不要回答,谢谢合作。
showeyes00:
还是不行,不知道为什么。
不知道你会不会使用cookie保存用户选项设置,就是用户点击英文或中文,然后使用cookie保存下来。下次就不用再选择了。
实在不行,使用javascript也可以。谢谢

PS附加:回答最好的将会得到价值200美元的回报!! 绝对无假!!输入邮箱地址(现建一个也无所谓,只要能收到邮件就行),我会将信息发到那里。
The person who gives the best answer will get a recieve of $200USD reward. NO SCAM! Enter your email (doesn't matter if you just create a new one, as long as you can recieve it then that is fine), and I will send you the details there.

这个问题有点小儿科,抱着所谓200美元的希望来回答这个问题.

记得付钱。。。需要改进的话再联系我。。。

<?php
// save the code as a file named index.php
// author : makerwang@gmail.com
$site = array(
'zh' => 'http://中文网站',
'en' => 'http://英文网站'
);

if ( isset($_GET['language']) && in_array($_GET['language'], array('zh', 'en'))) {
// 通过url强行指定语言index.php?language=zh|en
$_COOKIE['language'] = $_GET['language'];
header("Location:".$site[$_GET['language']]);
} else {
if ( isset($_COOKIE['language']) && in_array($_COOKIE['language'], array('zh', 'en'))) {
// 通过cookie取得语言
header("Location:".$site[$_COOKIE['language']]);
} else {
// 通过浏览器判断语言
if (preg_match("/zh-c/i", substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4))) {