admin管理员组文章数量:1326333
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.
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.
Share Improve this question edited Aug 23, 2012 at 14:14 Markus Hedlund 24.3k22 gold badges81 silver badges112 bronze badges asked Aug 23, 2012 at 8:35 user123_456user123_456 5,81526 gold badges87 silver badges142 bronze badges 4- Take a look at HTML 5 Web Storage – james lewis Commented Aug 23, 2012 at 8:38
- so instead of saving into session variables I am saving into web storage? – user123_456 Commented Aug 23, 2012 at 11:33
- Session ID can be passed via cookies or via GET method, and from what I know - browsers at mobile devices do support cookies. Are you sure your code actually works? Have you even started the session? – N.B. Commented Aug 23, 2012 at 12:00
- Bad idea since a lot of mobile devices don't have such capability. – Florent Commented Aug 23, 2012 at 12:05
3 Answers
Reset to default 6Cookies 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?
I had a similar situation and discovered that, before my tablet called the script I specified in the URL parameter of the .ajax( )
call, it was actually calling the index.php
script again.
Same with my phone. Since I had initialized my session variables in index.php
, they kept getting re-set to their initial values (making it look like they were not being correctly stored between pages).
I never figured out why index.php
was getting re-called, but I added if !isset( )
checks around the initialization statements and that cleared it up.
On Android, turning on "Data Saver" effectively destroyed my session. I have a login script which will redirect to the previous page when login succeeds. Worked until I turned on Data Saver. Turning it off made it work again. Google does state that Data Saver may affect secure pages which I guess includes my script, which is not on a HTTPS website.
本文标签: phpMobile browsers doesn39t support session variablesStack Overflow
版权声明:本文标题:php - Mobile browsers doesn't support session variables? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742201864a2432110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论