Session and register_globals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHP_learner
Forum Newbie
Posts: 1
Joined: Thu Dec 02, 2010 5:01 pm

Session and register_globals

Post by PHP_learner »

I'm a trying to build a multi-language website, the scenario is that the code checks if there's an existing session available, if not found will start a session with the default language, besides, when the user clicks on another labguage link, the code will set the language variable to the new language but I get a warning.

1st of all here's my code

Code: Select all

<?php

session_start();

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

?>
This code in a file that I include at the very top of every web page, the variable $lang is being sent as a parameter in url like : [text]<a href=#?lang=<?php echo $lang="de"?>'>Deutsch</a>[/text]

when I run the code, I get the following warning
[text]Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0[/text]

Ok, I got the point that I shouldn't use $_GET[] super global, but what's the other option that I have??
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Session and register_globals

Post by requinix »

PHP_learner wrote:Ok, I got the point that I shouldn't use $_GET[] super global, but what's the other option that I have??
Wrong. You're supposed to use it.

What you're not supposed to use is register_globals. Unless doing so will break your site, turn it off.
Post Reply