-1

I'm stuck with a small warning/error.

This is the errore: Notice: Undefined index: la in ****/layout/header.php on line 10

//select language
if (isset($_GET['la'])) {
$_SESSION['la'] = $_GET['la'];
header('location:'.$_SERVER['PHP_SELF']);
exit();

}
//language
switch ($_SESSION['la']) {
case 'en':
    require('lang/en.php');
break;
case 'it':
    require('lang/it.php');
break;
default:
    require ('lang/en.php');
break;
}

The problem is in the "switch". It all works but how can I fix the warning? I tried in some ways, but I went into ball!

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Marco
  • 37
  • 1
  • 10

1 Answers1

2

Notice: Undefined index: la

It means an index that you are using in condition its not defined.

Solution:

In your code you are missing to start your session, you need to start session at top level as:

session_start(); // add on top.

And for undefined index you need to declared session index in default.

$_SESSION['la'] = "";

Modified code:

session_start();
$_SESSION['la'] = "";
if (isset($_GET['la'])) 
{ 
   $_SESSION['la'] = $_GET['la'];    header('location:'.$_SERVER['PHP_SELF']); 
   exit(); 
} 

//language 
switch ($_SESSION['la']) 
{ 
   case 'en': require('lang/en.php'); 
   break; 
   case 'it': require('lang/it.php'); 
   break; 
   default: require('lang/en.php'); 
   break; 
}
devpro
  • 16,184
  • 3
  • 27
  • 38