I'm trying to add a cookie banner to my website and it has two different languages: Italian and English.
Language goes as
http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=eng
and
http://www.grcparfum.it/home.php?section=letteradelpresidente&lang=ita
and this is my code:
<?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; ?>
}
Problems you're probably encountering:
- Some curly brackets are outside of the scope of PHP
- It looks like you should be using
==
for the first if
statement not !=
.
- You're trying to compare a constant called
eng
with $currentlang
rather than "eng"
Try:
<?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 }
?>
I'm assuming it's never picking the eng
option.
I think your bug is not putting eng
in quotes:
if($currentlang !=eng){
Should be
if($currentlang != "eng"){