views:

124

answers:

3

Hello,

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.

A: 

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

Dormilich
So just create a link to a php scrip in html?
happyCoding25
A: 
<?php
// logout.php
session_destroy();

Then make a link to logout.php

webdestroya
+2  A: 

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?

Starx
Thanks for the reply. I don't need JavaScript but thanks for the offer.
happyCoding25