Search code examples
phpapachewampissetlitespeed

isset working on local server but not working on live server


I have a code that is working perfectly on my local server, but does not work on live server.

My local server is WAMP, while the live server is Unix with LiteSpeed, PHP and MySQL.

Problem is I want a new session to be created only if there is none existing. Please can anyone help with this?

The exact code is as follows:

$cart = $_SESSION["cart"];

if (isset($cart))// this checks if session has been created already.
$cart = $cart; // if session is already set, it uses the random value already created.
else {
$_SESSION["cart"] = rand(111111111,999999999);// if session has not be created        before a new randome number is picked.
$cart = $_SESSION["cart"];
}

Solution

  • This one should work anywhere:

    if(empty($_SESSION["cart"])){
        $_SESSION["cart"] = rand(111111111,999999999);
        $cart = $_SESSION["cart"];
    } else
        $cart = $_SESSION["cart"];