WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Use $_SESSION when writing a plugin (3 posts)

  1. David Gard
    Member
    Posted 2 years ago #

    Hey all,

    I'm writing a custom plugin that requires some form validate (only PHP, not JS), so I'm need to use $_SESSION to return the form values in the event of an error.

    Can anybody tell me where I need to add session_start(); (I'm guessing an action needs to be called, but I don't know which one), as everywhere I have tried has failed.

    Thanks.

  2. s_ha_dum
    Member
    Posted 2 years ago #

    Front end or back end?

  3. David Gard
    Member
    Posted 2 years ago #

    Back end. Think I have it now.

    I'm adding this to the __constructor function

    /** Initiate the session */
    session_start();

    And then this to the on_load_page() function ('load-{page}' action) -

    /** Unset and destroy the session (if necessary) */
    if(!empty($_SESSION) && !isset($_GET['status'])) :
    	session_unset();
    	session_destroy();
    endif;

    I then unset and destroy the session when the users action is succussful and the database is updated.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.