I was adding a multi-language system to my website, but came accross this error. Everytime I try to set some value on my $_SESSION, it says
Notice: Undefined index: lang in ...\pages\lang.php on line 3
What I noticed, is when I’m trying to set the $_SESSION on my core file, it works, but if I’m trying to include the file which sets the session to the core file, it throws out that error. Here’s the snippet of core.php:
<?php
session_start();
//some code
//if I type $_SESSION['lang'] = 'smth'; here, it will work
if (!isset($_GET['page']) || $_GET['page'] == "" || !file_exists('pages/'.$_GET['page'].'.php')) {
include 'pages/home.php';
} else {
include 'pages/'.$_GET['page'].'.php';
}
?>
pages/lang.php:
<?php
$lang = $_GET['lang'];
$_SESSION['lang'] == $lang;
var_dump($_SESSION); //prints an empty array ( array { } )
//header("Location: index.php");
?>
Any ideas? Thank you.
You need to include
session_start();in the start of every script that uses the $_SESSION variables.Also a typo:
$_SESSION['lang'] == $lang;should be just one ‘=’.