你可以试试这个
在你的头上这部分代码粘贴,并与你的网站URL代替anyone.com
<script type="text/javascript">
$(document).ready(function() {
if("<?php echo $timezone; ?>".length==0){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
$.ajax({
type: "GET",
url: "http://anyone.com/timezone.php",
data: 'time='+ visitortimezone,
success: function(){
location.reload();
}
});
}
});
</script>
并创建一个新文件timezone.php并在那里写入
<?php
session_start();
$_SESSION['time'] = $_GET['time'];
?>
并启动会议在头
<?php session_start(); ?>
当你保存的UserDetails到数据库中添加一个新的领域像GMTTIME并插入 $区值。
$timezone = $_SESSION['time'];
而且在头
添加jQuery的新代码将是
<?php
include 'con.php';
$token = $_GET['key'];
$sql = "Select * FROM userlogin WHERE token = '$token'";
$result = mysqli_query($connect,$sql);
$user = mysqli_fetch_array($result);
$time = $user['time'];
$gmt = $user['gmttime'];
$timezone2 = str_replace("GMT", "", $gmt);
$sec = 3600 * $timezone2;
$gmtdate = gmdate("Y-m-d H:i:s");
$current_time = date("Y-m-d H:i:s", strtotime($gmtdate) + ($sec));
$user_time = date("Y-m-d H:i:s", strtotime($time) + 1800);
if($current_time > $user_time) { // check if the current time is greater than $user['time']+30 minutes
exit("Link has expired");
}
else{
//your code part here
}
?>
时间将以哪种格式显示,你可以用那个更新你的问题吗? – rahulsm
它使用时间戳保存在sql中,它看起来像这样2017-04-17 13:00:00 @rahul_m – janejoe