Gayan
Gayan

Reputation: 2935

Wordpress session start front end

I am trying to create plugin in wordpress.. Plugin data direct to wordpress front end and I want stat wordpress session in front end using the plugin.

I tried using this but this is not working, can someone help me

function register_session()
{
  session_start();
}
add_action('init', 'register_session', 1);

Upvotes: 1

Views: 1164

Answers (1)

Nadeem Khan
Nadeem Khan

Reputation: 3434

Add this to your plugin or themes' functions.php template:

function register_session(){
if( !session_id() ) //checking if session already exists
    session_start();
}
add_action('init','register_session');

Then to set the session data use something like this:

$_SESSION['username'] = 'some data';

Upvotes: 2

Related Questions