- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SheetTime.php 是主页。当用户转到 SheetTime.php 时,他们将被重定向到 Login.php;如果他们在那里成功登录,他们将被定向到 SheetTime.php 的实际内容。
问题出在我的注销按钮上。当用户单击注销按钮时,他们总是被重定向到 SheetTime.php(页面似乎只是刷新),而不是实际注销并返回到 Login.php。我试图将 Logout.php 中的位置更改为 Login.php 并检查了 URL,但我得到了相同的结果。
我对为什么会出现此问题的理论是,因为我将 Logout.php 中的位置设置为 SheetTime.php,它会返回到 Login.php,然后返回到 SheetTime.php 等。几乎似乎被捕获了在这里循环,我对这些循环没有太多经验。
当用户单击注销按钮时,我希望他们退出站点并返回登录页面,以便他们可以再次登录该站点。有什么建议或者您看到我的代码有什么问题吗?
注销.php:
<?php
session_start();
unset($_SESSION["STYLE"]);
header("Location: SheetTime.php");
?>
工作表时间.php:
<?php
session_start();
$user_name = $_SESSION['STYLE'];
//----------- Check if any user is currently logged in ---------------
if (!(isset($user_name) && $user_name!= '')) {
header("Location: http://www.websitetotestfortest.edu/theTimePro/Login.php");
}else{
// (***there is other code in between***)
//------------- Logout Button (Terminates session) ------------------
echo "<br /><form action='Logout.php' method='post'>
<input value='Log out' id='Submit' type='submit' /></td>
</form>";
?>
登录.php
session_start();
$_SESSION['STYLE'] = phpCAS::getUser();
//$_SESSION['STYLE'] = $row['STYLE'];
$URL="http://www.websitetotestfortest.edu/theTimePro/SheetTime.php";
header ("Location: $URL");
?>
最佳答案
Logout.php
<?php
session_start();
unset($_SESSION['style']); //unset will work fine for a specifik session variable. If you want to get rid of all **your** active sessions for your domain use session_destroy();
session_destroy();
header("Location: Login.php");
exit;
?>
SheetTime.php
<?php
session_start();
if(!isset($_SESSION['style']) || $_SESSION['style'] == '')){
header("Location: http://www.websitetotestfortest.edu/theTimePro/Login.php");
exit;
}
//There's a valid session, so do things here.
登录.php
<?php
session_start();
if(isset($_POST['doLogin'])){
$db = new PDO("..."); //your database details
$statement = $db->prepare("SELECT id FROM your_user_table WHERE username = :username AND password = :password");
$statement->execute(array(':username' => $_POST['userName'], ':password' => $_POST['passwd']));
$count = $statement->rowCount();
if($count <= 0){
header("Location: login.php?error"); //go here if there's an error... receive it with if(isset($_GET['error'])){ echo 'your text';}
exit;
}
$row = $statement->fetch(); // if a result was found, fetchit
$_SESSION['style'] = 'yourValue'; // define the session variable
header("Location: Path-To-SheetTime.php");
exit;
}
?>
<form method="post" action="login.php">
<!-- your login form -->
<input type="text" name="userName"/>
<br/>
<input type="password" name="passwd"/>
<br/>
<input type="submit" name="doLogin" value="Login"/>
</form>
编辑此外,我看不出你用 session 变量的值声明 $user_name 的任何原因。在我的示例中,您可以完美地验证 session 变量中的信息,而无需将其声明为另一个变量。如果 $_SESSION['style'] 令人困惑(是的,确实如此!!:))那么 $_SESSION['user_name'] 可能更有意义。
编辑2我在登录中添加了数据库验证。在此处查看 PDO 以获取更多信息 http://www.php.net/manual/en/book.pdo.php
至于注销.. 我假设所有这些文件都位于同一台服务器上,并且您确实确保 $_SESSION['style'] 以相同的方式编写。小心帽子。
进入文件时,应该取消设置 session 。请尝试添加 session_destroy();低于 unset 以确保。
添加注销链接很简单:
<a href="the-path-to-logout.php">Logout</a>
然后注销将终止事件 session 并将您重定向到 login.php。确保所有路径都正确。
关于php - 注销按钮将用户重定向到同一页面,而不是将用户注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24018365/
我正在进行 Twitter 集成。 我不知道如何退出 Twitter。 我正在使用以下代码尝试注销...但它只是删除了 token : try {
我可以使用我的站点和 phpBB3 的集成登录系统登录。我不能 注销...我尝试破坏 session ,或使用 ->logout(); 我登录为: $phpBBusername = $_SES
我目前正在学习 firebase facebook auth,但似乎 firebase 不提供 facebook logout api? 因为我在 firefeed.io 上注销,但它并没有注销 fa
环境 Richfaces 3.3.3 JSF 1.2 站点记录器 要求 用户输入所需的申请地址。 Siteminder 拦截并询问用户名和密码。客户提供凭据。客户使用应用程序并单击注销/退出按钮。应用
我喜欢从 Azure 广告 B2C 中注销我的 Web 应用程序。我尝试了以下示例 https://www.janaks.com.np/azure-ad-identity-provider-in-as
通过使用 here 中的 Fitbit 文档。我已在我的应用程序中成功通过 token 过期时间 expires_in=604800 进行 Fitbit 身份验证。我对如何从登录帐户注销感到困惑。是否
我有一个使用 Oauth 2 与 Facebook 集成的应用程序。 我可以使用 FB 授权并很好地查询他们的 REST 和图形 API,但是当我授权时,一个事件的浏览器 session 是使用 FB
在我的应用程序中,我有一个将 BroadcastReceiver 注册到 onStart() 方法中的服务: public void onStart() { if(something....)
我有一个 div 标签,可以说“mydivTag” 它下面有一个子节点,ID为“childID” 我想删除/取消注册/任何“childID”,然后重新创建具有相同 ID“childID”的不同节点 如
我有一个 asp.net 应用程序,我正在使用 FormsAuthantication。当用户关闭页面时,位于 Global.asax Session_End 中的代码被执行:FormsAuthant
我的应用程序的结构如图所示。 在我的 ProfileViewController(选项卡之一)中,有一个注销按钮。 我想弹出回到 RegisterViewController。 如果用户已经注册,我将
有没有办法注销在 php 中完成的摘要式身份验证。 我试过 unset($_SERVER["PHP_AUTH_DIGEST"]);但它不会要求重新登录。我知道如果我关闭浏览器它就会工作,这是我的功能。
我的问题是捕获用户注销。我的代码是: public function onAuthenticationFailure(Request $request, AuthenticationExceptio
我下面的代码是应用程序的 OnClick 注销方法。目前它所做的只是将用户返回到登录页面,但是如果用户按下 Android 手机上的后退按钮,它会将他们带回到他们刚刚注销的页面,我不希望这样.如何更改
我有一个带有面板的表单,我可以在该面板上动态加载多个用户控件。我处理每个控件的事件。 UserControl userControl1 = LoadControl("control.ascx") as
我正在尝试为我们现有的 laravel 站点(laravel 5.2)的注销功能添加一些逻辑,但它不像登录那样简单。 客户端的现有注销工作正常,但我想要做的就是向我的 Cognito 实例添加一个调用
当前从注册处注销 M3 模型的首选方法是什么? 在我的项目中,我使用 Rascal 来分析大约 100 个大型 Java 程序,而我的 JVM 正在慢慢耗尽内存。我在旧版本的注册表中找到了 unreg
此主题与 Java 中的主题相关,但我找不到 C# 的解决方案。 http://theblasfrompas.blogspot.com/2010/01/closing-obsolete-databas
Slick 用大量的日志消息填满了控制台。我想,就像文档建议的那样,使用 slf4j-nop ,所以日志是关闭的,但是 Akka 需要自己的 slf4j 库。 所以我只剩下 akka-slf4j_2.
如果他空闲 20 分钟,我想提醒用户。所以,创建了一个服务。 它在桌面上运行良好,但在手机中它没有显示,有时如果屏幕在后台停留了几个小时,那么一旦我再次进入页面,注销对话框屏幕就会开始倒计时。 我的意
我是一名优秀的程序员,十分优秀!