在
PHP中,我想在单击按钮时更改站点的语言(英语,德语等).这是解决这个问题的正确方法吗?
<?PHP $language; if ($language == "en") { include("headerEn.PHP"); } else { include("header.PHP"); } ?> <a href="index.PHP"><?PHP $language = "en"; ?> <img src="images/language/languageNO.png"></a> <a href="index.PHP"><?PHP $language = "no"; ?> <img src="images/language/languageEN.png"></a>
你可以做到这一点
<a href="index.PHP?language=en"> <a href="index.PHP?language=no">
并获取语言并将它们存储在cookie中并根据cookie包含文件
if ( !empty($_GET['language']) ) { $_COOKIE['language'] = $_GET['language'] === 'en' ? 'en' : 'nl'; } else { $_COOKIE['language'] = 'nl'; } setcookie('language',$_COOKIE['language']);
然后
if ( $_COOKIE['language'] == "en") { include("headerEn.PHP"); } else { include("header.PHP"); } ?>