3

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

3 Answers 3

14

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?

1
  • Thanks for the reply. I don't need JavaScript but thanks for the offer.
    – nosedive25
    May 22, 2010 at 19:35
1
<?php
// logout.php
session_destroy();

Then make a link to logout.php

0

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

1
  • So just create a link to a php scrip in html?
    – nosedive25
    May 22, 2010 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.