我试图在我的网站上添加Cookie横幅,它有两种不同的语言:意大利语和英语。
语言为
http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=eng
和
http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=ita
这是我的代码:
<?php
$currentlang= $_GET['link'];
if($currentlang !=eng){
?>
<script src="/js/cookiechoices-en.js"></script>
}
<?php else: ?>{
<script src="/js/cookiechoices-it.js"></script>
<?php endif; ?>
}
答案 0 :(得分:0)
您可能遇到的问题:
==
作为第一个if
语句而不是!=
。eng
的常量与$currentlang
进行比较而不是"eng"
<强>尝试:强>
<?php
$currentlang = filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_STRING); // Safer
if($currentlang == "eng"){ ?>
<script src="/js/cookiechoices-en.js"></script>
<?php } else { ?>{
<script src="/js/cookiechoices-it.js"></script>
<?php }
?>
答案 1 :(得分:0)
我假设它从未选择eng
选项。
我认为您的错误不是将eng
放在引号中:
if($currentlang !=eng){
应该是
if($currentlang != "eng"){
答案 2 :(得分:0)
使用JQuery执行此操作:
LeafType2
&#13;
url = 'http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=eng';
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(url);
// results = regex.exec(location.search); gets the url of current window
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var language = getParameterByName('lang');
english = '<script src="/js/cookiechoices-en.js"><\/script>';
italian = '<script src="/js/cookiechoices-it.js"><\/script>';
if(language == 'eng'){
$('#script').html(english);
}else if(language == 'ita'){
$('#script').html(italian);
}
&#13;