May 22, 2010

PHP Link to session_destroy

Question by nosedive25

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.

Answer by Starx

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?

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!