删除Cookie PHP [英] Delete cookie php
本文介绍了删除Cookie PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试建立一个具有登录系统的平台,并且将用户名和密码存储在cookie中,以使用户保持登录状态,即使它关闭了浏览器然后再次输入也是如此.我设法保存了cookie,但是我不知道如何进行注销按钮. 这是代码:
I am trying to make a platform with a login system and I am storing the username and the password in cookies to make the user stay logged in even if it closes the browser and then enters again. I managed to save the cookies but I don't know how to make the logout button. Here is the code:
function logout() {
$('body').append("<?php setcookie('username', null); setcookie('password', null); unset $_COOKIE['username']; unset $_COOKIE['password']; ?>");
location.assign("index.php");
}
推荐答案
您正试图将PHP代码包含在JavaScript中,但这样无法正常工作. 您可以按照建议的此处:
You are trying to include PHP code in JavaScript, which will not work like that. You could either delete the cookie with jQuery as suggested here:
function logout() {
$.cookie("username", null, { path: '/' });
location.assign("index.php");
}
或通过使用以下PHP代码调用PHP文件:
or by calling a PHP file with the following PHP code:
setcookie("username", "", time() - 3600, '/');
这篇关于删除Cookie PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文