你可以試試這個
在你的頭上這部分代碼粘貼,並與你的網站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