How to destroy the php session with one button

前端 未结 2 437
梦如初夏
梦如初夏 2020-12-11 23:31

I\'d like to make a simple form button which completely destroys the session when you click on it. I am just starting to use PHP for the first time, and do not see how I imp

相关标签:
2条回答
  • 2020-12-12 00:02

    index.php

    <?php session_start(); ?>
    
    <form action="clear-session.php" method="POST">
        <input type="submit" value="Clear session" />
    </form>
    

    clear-session.php

    <?php session_start();
    
    session_destroy();
    header('Location: index.php');
    exit();
    ?>
    
    0 讨论(0)
  • 2020-12-12 00:05

    The form button is just like any other form button, nothing special. Catch the POST on the php side of things, and use session_destroy(); to kill the session data entirely.

    See this guide for info about forms and post if you're hazy on the subject: http://www.tizag.com/phpT/postget.php and this http://www.tizag.com/phpT/phpsessions.php for info about sessions

    More info about forms and PHP and how to work with the data from the form: http://www.tizag.com/phpT/forms.php

    Example:

    Order.html:

    <html><body>
    <h4>Tizag Art Supply Order Form</h4>
    <form action="process.php" method="post">
    <input type="submit" />
    </form>
    </body></html>
    

    process.php:

    <html><body>
    <?php
    session_destroy();
    ?>
    </body></html>
    

    It's cheesy...does this help?

    0 讨论(0)
提交回复
热议问题