嘿,伙计们真的是php中的一个小人物。。。我只想在会话结束后重定向。。所以我知道,如果没有js,这是无法实现的。。所以我在朋友的帮助下修改了代码
<html>
<body>
<?php
session_start();
$_SESSION['logintime'] = time();
echo 'this page needs to be redirected in a minute'
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
$(function(){
var loginTime = <?php echo $_SESSION['logintime']; ?>
var testSession = setInterval(function(){
var currentTime = Date.now() * 1000;
if((currentTime - loginTime) > 60) { //here 60 denotes a minute
<?php session_start();
session_unset();
unset($_SESSION);
session_destroy();
?>
window.location.href = 'www.google.com'; // redirecting process
}
}, 1000);
});
</script>
</body>
</html>
代码运行时没有错误。。但它在60秒后不会重定向。。
任何使此代码正确工作的指南都将不胜感激。。Thanx
试试这个,它会出现在html的部分:仅使用html
<meta http-equiv="refresh" content ="5; url=http://www.target.com/">
5是秒数。现在,您可以用一些PHP生成的值替换5。
<meta http-equiv="refresh" content ="<?php echo $limitTime(); ?>; url=http://www.target.com/">
如果您想在Javascript中执行此操作,请使用以下语法
setInterval(function () {window.location.href = 'http://www.google.com'}, 60000)
在php中,您可以使用头方法重定向url
header("Location: http://www.google.com")