Search code examples
phpjavascriptmobilecookiesjquery-mobile

Mobile browsers doesn't support session variables?


I have a browser version of my web app and I have some values stored in cookies. Now I am making a mobile version and it seems that my cookies are not working. Is it possible to use cookies on mobile devices?

I am trying to perform this code and my php is giving me an empty value:

$(document).ready(function() {
    var session_lang= '<?php if(isset($_SESSION['SESS_LANGUAGE']))
                            echo $_SESSION['SESS_LANGUAGE'];?>';
            if (session_lang!='')
            {
                check_and_change(session_lang);   
            }
    });

Is there any other way to store data in internal memory so it can work as cookie? Does mobile devices support session variables? I am looking on the firebug and I can see that I can create session variable but when I want to read it it is null. What could be a problem and how to solve this?

EDIT: I will put you almost entire code so you can see what am I doing...btw. this code is working normally on PC browser.

Javascript file:

$(document).ready(function() {

    function languageChange()
    {
         var lang = $('#websites1 option:selected').val();

        return lang;
    }


    $('#websites1').change(function(e) {                    

        var lang = languageChange();

        var dataString = 'lang=' + lang;

        $.ajax({

            type: "POST",
            url: "pass_value.php",
            data: dataString,
            dataType: 'json',
            cache: false,
            success: function(response) {

                    check_and_change(response.message);
                 }
        });

        return false;

    });

} );

    function check_and_change(lang)
     {
            switch (lang)
                         { //do something
                          }
    }

Then this first part that I have put above is on the actual php site that I am looking and which is opening:

And the last thing is pass_value.php:

<?php 
session_start();

$_SESSION['SESS_LANGUAGE'] = $_POST['lang'];

print json_encode(array('message' => $_SESSION['SESS_LANGUAGE']));
die();
?>

I really don't know why this code doesn't work on the mobile phones.


Solution

  • Cookies definitely work on mobile browsers. You say "I am looking on the firebug" which makes me think you aren't really looking at it on a phone.

    Have you started the session, and turned on error reporting?