0

I have to check the session value, and check it with the constant/defined value and perform action.

The below code is not working. What I'm tyring to do is.

if the session value is A, then check it against the list array(i.e $get_abc), and perform some task if the session value is E, then check it against the list array(i.e $get_ef), and perform some task

    <?php
    $_SESSION['get_value'] = "A";

    define ("ABC", serialize (array ("A", "B", "C")));
    define ("D", serialize (array ("D")));
    define ("EF", serialize (array ("E","F")));

    $get_abc = unserialize(ABC);
    $get_d = unserialize(D);
    $get_ef = unserialize(EF);

    if (in_array($_SESSION['get_value'], $get_abc)) {
        .. do abc stuff..
    }else if(in_array($_SESSION['get_value'], $get_d)) {
        .. do d stuff..
    }else if(in_array($_SESSION['get_value'], $get_ef)) {
        .. do ef stuff..
    }else{
        .. do simple query..
    }
    ?>

Any help

25
  • 2
    try adding session_start(); function at the top of file. Commented May 30, 2014 at 12:47
  • 1
    Sidenote: You need to mention if session_start(); is indeed loaded. If so, include it in your question/code. If you're not loading it, do. Commented May 30, 2014 at 12:48
  • 1
    @Fred-ii- yes :-) BUT, let me try something else. I did forget to DEFINE ABC. Once I do that it work fine. :-/ Commented May 30, 2014 at 12:57
  • 1
    We're not confused @RahilWazir, we just haven't had proper amounts of caffeine yet. Commented May 30, 2014 at 13:03
  • 1
    @JayBlanchard Ah ok. I just finished it :) Commented May 30, 2014 at 13:05

1 Answer 1

2

try to add session_start()

<?php session_start();
    $_SESSION['get_value'] = "A";
    define ("ABC", serialize (array ("A", "B", "C")));
    define ("D", serialize (array ("D")));
    define ("EF", serialize (array ("E","F")));

    $get_abc = unserialize(ABC);
    $get_d = unserialize(D);
    $get_ef = unserialize(EF);

    if (in_array($_SESSION['get_value'], $get_abc)){
      echo 'do abc stuff..';
    }else if(in_array($_SESSION['get_value'], $get_d)) {
        echo 'do d stuff..';
    }else if(in_array($_SESSION['get_value'], $get_ef)) {
        echo ' .. do ef stuff..';
    }else{
         echo '.. do simple query..';
    }
    ?>

output :- do abc stuff..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.