vie vie - 4 months ago 7x
PHP Question

Checking if SESSION value

I want to check session data. The value of $_SESSION['yatidak'] is 'Tidak', but i can't check the condition. Why? Please see the code

$yt = $_SESSION['yatidak'];
echo $yt;
// output : Tidak

if ($yt=='Tidak') {
echo 'Tidak';
echo 'Iya';
// output : Iya

Echo should be :

// TidakTidak

But the result is :

// TidakIYa


The actual process is you have to do is,

session_start(); //at the very first line of the page
//Check the session value direct to the string and use trim if some white spaces are there should be removed and also use `===` which match type and data both
if (trim($_SESSION['yatidak']) === "Tidak") { 
    echo 'Tidak';
    echo 'Iya';
// output sould be: Tidak