The Little Guy Posted April 9, 2007 Share Posted April 9, 2007 Why isn't this working? It changes the cookies in the browser, but when I go to get the cookie, It hasn't changed. In FF, if I go into the preferences and view the cookies, the content of language has changed. When I do echo $_COOKIE["language"]; It hasn't changed. <?php if (!isset($_COOKIE['language']) || isset($_GET['language'])){ if($_GET['language']=='english'){ setcookie("language", 'english', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; } elseif($_GET['language']=='spanish'){ setcookie("language", 'spanish', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; } elseif($_GET['language']=='german'){ setcookie("language", 'german', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; }else{ $_COOKIE["language"] = 'english'; } } include $_COOKIE["language"].'.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/ Share on other sites More sharing options...
The Little Guy Posted April 9, 2007 Author Share Posted April 9, 2007 languages.php <?php if (!isset($_COOKIE['language']) || isset($_GET['language'])){ if($_GET['language']=='english'){ setcookie("language", 'english', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; } elseif($_GET['language']=='spanish'){ setcookie("language", 'spanish', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; } elseif($_GET['language']=='german'){ setcookie("language", 'german', time()+25920000); header("Location:".$_SERVER['HTTP_REFERER']); exit; }else{ $_COOKIE["language"] = 'english'; } } ?> index.php <?php session_start(); include"db.php"; include"languages/language.php"; include'languages/'.$_COOKIE["language"].'.php'; Quote Link to comment https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/#findComment-224793 Share on other sites More sharing options...
dsaba Posted April 9, 2007 Share Posted April 9, 2007 <?php if (!isset($_COOKIE['language']) || isset($_GET['language'])){ if($_GET['language'] == "english"){ setcookie("language", 'english', time()+25920000); exit; } elseif($_GET['language'] == 'spanish'){ setcookie("language", 'spanish', time()+25920000); //header("Location:".$_SERVER['HTTP_REFERER']); exit; } elseif($_GET['language'] == 'german'){ setcookie("language", 'german', time()+25920000); //header("Location:".$_SERVER['HTTP_REFERER']); exit; }else{ $_COOKIE['language'] = 'english'; } } else { echo $_COOKIE['language']; } ?> try that, i took out your headers, and i passed an uknown GET like ?language=dontsetcookie and it works fine you can't echo cookies on the same page load that you set them and the headers seemed to be a problem for me Quote Link to comment https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/#findComment-224799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.