Thread

Set PHP session on one page and access on different page

October 10, 2017 7:39am

Subscribe [1]
  • #1 / Oct 10, 2017 7:39am

    deswork

    78 posts

    Hi,

    I’ve enabled PHP in a number of templates in a template group. I want to restrict access to certain templates based on a session been set. When a visitor submits a form it creates a session and redirect to a competition entry page, see code below.

    $_SESSION["entered_code"] = "submitted";
    header( 'Location: domain.com/henry/entry/'.$code ) ;

    On the entry page I want ot check if the session has been set, if not redirect the visitor back to the index page.

    if( ! isset($_SESSION["entered_code"])){
     header( 'Location: domain/henry' ) ;
    }

    The problem is the session id on the entry page is different to the id on the page where I want to check the session, so the session is not available.

    Is there a way to set and acces PHP sessions across different pages.

    Thanks

    Wayne.

ExpressionEngine News

#eecms, #events, #releases