简体   繁体   English

PHP链接到session_destroy

[英]PHP Link to session_destroy

I need to make a link that when clicked will run this in php: 我需要创建一个链接,点击后将在php中运行:

session_destroy();

I know how to make a link in html, but I don't know how to make it interact with php. 我知道如何在html中建立链接,但我不知道如何使它与PHP交互。 Thanks for any help. 谢谢你的帮助。

For an example, you want to use this script for logging out. 例如,您希望使用此脚本进行注销。

Your HTML has to be something like this for "index.php" (just an example) 对于“index.php”,你的HTML必须是这样的(只是一个例子)

<a href="logout.php">Log Out</a>

Then on the "logout.php" 然后在“logout.php”

session_start(); //to ensure you are using same session
session_destroy(); //destroy the session
header("location:index.php"); //to redirect back to "index.php" after logging out
exit();

In case you want to use JavaScript, I can tell you that too? 如果你想使用JavaScript,我也可以告诉你吗?

<?php
// logout.php
session_destroy();

Then make a link to logout.php 然后建立一个logout.php的链接

你需要做的就是调用一个调用该函数的PHP脚本。

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

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