Javascript位置重载没有get周长
Javascript location reload without get perimeter
如何使" location.reload()
"在php文件没有得到周长?
下面是一个例子…
假设我有PHP,在右上方,我有一个注销按钮。
当用户按下该按钮时,PHP将自动重定向到"index.php?logout
",然后退出(取消cookie和其他设置),并将( javascript location.reload() )
返回主页(登录页面)
我遇到的问题是,当php退出后返回登录页面时,url仍然是"index.php?logout
",所以当用户登录回"index.php?logout
"页面时,它会自动退出(因为url上的退出周长).
那么我该如何解决这个问题呢?有人知道吗?
我希望你们都能理解我想告诉你们的一切。
谢谢你的阅读…
使用self.location.reload
代替location.reload
。因为location.reload
会重新加载当前页面。你可以简单地使用
self.location.reload = index.php
或者您可以从url中删除查询参数,如
var url = 'index.php?logout'
url=url.split("?")[0];
location.reload =url
location.reload()用post数据重新加载当前页面,您应该在登录/注销
当用户按下该按钮时,PHP将自动重定向到"index.php? "之后,我将注销(取消cookie和其他设置)并返回(javascript location.reload()>)到主页(登录页)
这些都可以在服务器端实现。
// LOGOUT
if(isset($_GET['logout'])){
//logout code
}
header('location: www.yoursite.com/login') //or whatever the url is
exit;
您重定向到登录页面并保存请求登录的页面url,这是index.php?logout
,对于重定向,您必须检查外围logout
,如果存在,将其从返回url中删除,例如
//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
存在于返回url中,删除它
我希望它能帮助你
- 有没有一种方法可以防止img get请求使用css或js发生
- CORS-重定向到第二个GET正在接收的页面
- jQuery Ajax GET请求工作不正常
- 如何将PHP get查询转换为Meteor's HTTP.get()
- 返回/从Twit's客户端.get
- AngularJS错误:提供程序必须从$get工厂方法返回值
- 如何在router.get()方法中传递url作为参数
- 使用Javascript/JQuery获取JSON GET数据
- 如何使用php文件中的GET来获取我在.js文件中声明的变量
- Get方法获取csv文件的内容
- 什么'$.get和$.ajax之间的区别是什么
- I'我得到这个.get()在ember中未定义
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- Datatable get列值只给出前10行
- Angularjs http.get() Cross-Origin 请求被阻止
- Angular js http get返回所有页面
- Get JSON from an url
- 将GET请求(HTML字符串)转换为完整的DOM对象
- regex get id imgur embed?
- Javascript位置重载没有get周长