Jump to content

Recommended Posts

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';
?>

Link to comment
https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/
Share on other sites

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';

Link to comment
https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/#findComment-224793
Share on other sites


<?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

Link to comment
https://forums.phpfreaks.com/topic/46232-solved-cookie-issues/#findComment-224799
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.