简体   繁体   English

使用Cookies php注销

[英]logout using cookies php

This is the way i set cookies for authentication purpose, but i need a logout function to destroy those cookies...and send back to index page, please help me out?? 这是我出于身份验证目的设置cookie的方式,但是我需要注销功能才能销毁这些cookie ...并发送回索引页面,请帮帮我吗?

<?php
require_once('Template.php');
require_once('common/common.php');

$mes="";
if($value['m']==1)
 {
    $mes="Invalid Username / Password.";
    setcookie("USERNAME", "", time()-3600);
 }

$template =& new Template('html/login.html');
$template->AddParam('mes',$mes);
$template->EchoOutput();

?>

actually i forgot to post the login authentication code... 实际上我忘记发布登录验证码...

<?php
 require_once('class/User.php');
 require_once('common/common.php');
 $user= new User();

 $user->getUser($value['username'],$value['password']);

 if($user->ID != null){
setcookie("USERNAME", $user->USERNAME);
header("Location:adminhome.php");

  }
 else
 {
 header("Location:index.php?m=1");
 }
  ?>

logout.php:

setcookie("USERNAME" , '' , time()-50000, '/');
header("Location: index.php");
exit;

add a link to logout.php . 添加一个链接到logout.php logout.php should contain the code above. logout.php应该包含上面的代码。

setcookie("USERNAME" , '' , time()-50000, '/'); setcookie(“ USERNAME”,'',time()-50000,'/');

this destroys the cookie. 这会破坏cookie。

header("Location: index.php");
exit;

this redirects the user to index.php 这会将用户重定向到index.php

I've removed the if statement cause i've realised it's not useful here 我删除了if语句,因为我意识到这里没有用

You are currently unsetting the cookie in your example. 您当前正在示例中取消设置Cookie。 Also, setting a cookie with no value is the same as deleting it. 另外,设置没有值的cookie与删除它相同。 Then simply redirect to your landing page after logout. 然后在注销后直接重定向到您的登录页面。

setcookie( 'cookie_name'); // deletes the cookie named cookie_name
Header("Location: url.com");

You might want to add an exit(); 您可能想要添加一个exit();。 statement after the call to Header(). 调用Header()之后的语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM