vie vie -5 years ago 165
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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download