[英]undefined index while trying to echo a variable $_SESSION, php jquery ajax,
edit i am not getting the error undefined index 'time' any longer. 编辑我不再得到错误未定义的索引“时间”。 Now i am not getting any errors, but when i try echoing $timezone;
现在我没有任何错误,但是当我尝试回显$ timezone时; nothing happens.
什么都没发生。
what am i missing here that is causing the undefined index 'time'? 我在这里错过了什么导致未定义的索引“时间”? i do have jquery in the page.
我在页面中有jquery。
index.php index.php
<?php
session_start();
$timezone=$_SESSION['time'];
?>
script, using jquery to get the time and then setting it as a $_SESSION['time'] variable. 脚本,使用jquery获取时间,然后将其设置为$ _SESSION ['time']变量。
<script>
$(document).ready(function() {
if("<?php echo $timezone; ?>".length==0){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
$.ajax({
type: "GET",
url: "<?php echo $_SERVER['DOCUMENT_ROOT'].'/social_learning/php/timezone.php';?>",
data: 'time='+ visitortimezone,
success: function(){
location.reload();
}
});
}
});
</script>
timezone.php timezone.php
<?php
session_start();
$_SESSION['time'] = $_GET['time'];
?>
just change $timezone=$_SESSION['time'];
只需更改
$timezone=$_SESSION['time'];
to $timezone=isset($_SESSION['time'])?$_SESSION['time']:"";
到
$timezone=isset($_SESSION['time'])?$_SESSION['time']:"";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.