duanmeng7865 2013-09-27 06:51
浏览 44
已采纳

多语言网站:php + mysql + cookies

I have coded a multilingual web with php & mysql. Now I've faced problems (mainly with robots, seo and search engines) because language chooser is based on cookies.

how it works now: user => index.php :

function cookies() {
 if (!isset($_COOKIE["lang"])){
 setcookie('lang','ukr', time()+(60*60*24*31)); 
 header('Location: index.php');  
}};

and outputting chosen language to every place it needed to be with the function:

function catSet($source, $link, $item){
 $item .= '_'. $_COOKIE['lang'];
 global $connection;
 $link = mysqli_real_escape_string($connection, $link);
 $result = mysqli_query($connection, "SELECT * FROM  $source WHERE link_item = '". $link ."'");
if (!$result) { die("DB Query failed: " . mysql_error()); }
while ($row = mysqli_fetch_array ($result)) {
 echo $row[$item]; }}

What I want now is to have $item .= '_'. $_COOKIE['lang']; to be replaced with constant based on a user choice which would be readable by robots and search engines, so it's a must it's not a cookie.

I don't want to use session, because this way user have to re-choose language each time after session expires.

AFAIK there is no way to detect browsers language, to set it as default.

I see a way out to use [GET] variable instead, and pass it each time to other page, but how to store this [GET] data if user come back next time (same problem as with sessions).

I would appreciate any ideas and solutions :)

  • 写回答

2条回答 默认 最新

  • dongliaoqiang8524 2013-09-27 06:54
    关注

    You can still use cookies to save user decision. When user visit your website without language in url (GET) but got cookie with selected language, redirect him to url with selection.

    It'll allow you to use addresses with given language and also will allow user to just copy/past his current URL which will always lead him to his language version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备