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条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?