PHP Link to session_destroy

流过昼夜 提交于 2019-12-13 14:42:06

问题


I need to make a link that when clicked will run this in php:

session_destroy();

I know how to make a link in html, but I don't know how to make it interact with php. Thanks for any help.


回答1:


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)

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

Then on the "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?




回答2:


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

Then make a link to logout.php




回答3:


all you need to do is call a PHP script, which calls that function.



来源:https://stackoverflow.com/questions/2889434/php-link-to-session-destroy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!