开发者

php Aruba $_session issue

I'm testing this code in Localhost and on Server "Aruba".

In local environment it works perfectly while on Server I dont have the expected session value

When I echo out the $_SESSION['lang'] it outputs :

-the correct country code (Ex.'en') in localhost

-On the Aruba server $_SESSION['lang'] outputs the array named $lang (that you can find on lang.en.php)instead of the needed country code!!

Where am I wrong?

thanks

Luca

my home.php

require_once('/web/htdocs/www.mywebsite.com/home/includes/langSwitcher.inc');
echo $_SESSION['lang'];
[..]

my langSwitcher.inc

session_start();
header('Cache-control: private'); // IE 6 FIX

if(isset($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_SESSION['lang'] = $lang;

setcookie('lang', $lang, time() + (3600 * 24 * 30));
}

else if(isset($_SESSION['lang']))
{
$lang = $_SESSION['lang'];  
}

else if(isset($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
$_SESSION['lang']=$lang;
}
else
{
$lang = 'en';
$_SESSION['lang']=$lang;

}
开发者_StackOverflow社区
switch ($lang) 
{
 case 'en':
 $lang_file = 'lang.en.php';
 break;

 case 'it':
 $lang_file = 'lang.it.php';
 break; 

}

include_once $lang_file;

my lang.en.php

/*
-----------------
Language: Italian
-----------------
*/



$langcode='en';

$lang = array();

$lang['PAGE_TITLE'] = 'pagetitle';

$lang['HEADER_TITLE'] = 'title header ';

$lang['SITE_NAME'] = 'name site';

$lang['HEADING'] = 'title';


It sounds like register_globals may be enabled (although that feature is deprecated). You can find out by running a phpinfo() and looking for the register_globals entry.

Assuming it is enabled, the only solution is to fix it in php.ini (you cannot override register_globals with an ini_set() call).


Well you are using $lang to keep the langcode, but also to store the array information. Perhaps in the langSwitcher.inc you should be using $langcode to store the session?

Because you are also settings the $lang var in the session their. On your server it seems to be using a reference to the $lang file, and therefor outputting the latest content set to $lang (which is the array) and on local it is storing the actual content of $lang.

Anyway, it can be solved by not using the same variable name to store two different items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜