如何在没有获取周边的情况下在php文件上创建“location.reload()
”?
这是一个例子..
假设我有PHP,在右上角,我有注销按钮。
当用户按下该按钮时,PHP将自动重定向到“index.php?logout
”,之后,我将注销(取消设置cookie和其他)并将( javascript location.reload() )
返回到主页面(登录页面)
我遇到的问题是,当注销后php返回登录页面时,url仍为“index.php?logout
”,因此当用户使用“index.php?logout
”页面返回时,它会自动注销(因为网址上的“注销周界”.. ..
那么我该如何解决这个问题呢?有人有任何想法吗?
我希望你们都明白我要告诉你的一切......
感谢您阅读此内容..
答案 0 :(得分:1)
使用self.location.reload
代替location.reload
。因为location.reload
重新加载当前页面。你可以简单地使用
self.location.reload = index.php
或者您可以从您的网址中删除查询参数,例如
var url = 'index.php?logout'
url=url.split("?")[0];
location.reload =url
答案 1 :(得分:0)
您重定向到登录页面并保存页面网址请求登录index.php?logout
以便重新直接返回您必须检查周边logout
如果存在,请将其从返回网址中删除,例如
//replace parent::$Patch with your root url like "http://localhost/myapp/"
if(!parent::$Patch.'admin/login.php'=='http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']){//check if you are in login.php page didn't redirect to login.php
if(!@header('Location:'.parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])))){
//if header error echo javaScript code for re-direct
?>
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript">
var LoadP = <?php print "'".parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))."'"?>;
self.location = LoadP;
</script></head></html>
<?php
}
exit();
}
}
此代码将用户重定向到登录页面并保留页面的返回URL。如果返回网址中存在logout
,请将其删除
我希望它可以帮到你
答案 2 :(得分:0)
location.reload()使用发布数据重新加载当前页面,如果是登录/注销,则应使用window.location.href
答案 3 :(得分:0)
当用户按下该按钮时,PHP将自动重定向到“index.php?logout”和&gt;之后,我将注销(取消设置cookie和其他)并返回(javascript location.reload()&gt;)到主页面(登录页面)
所有这些都可以在服务器端实现。
// LOGOUT
if(isset($_GET['logout'])){
//logout code
}
header('location: www.yoursite.com/login') //or whatever the url is
exit;