Session lost after form submit in wordpress
You have to call always session_start() for each request.
The mission of session_start() is:
- Creates a new session
- Restart an existing session
That means, if you have created a session, and you don't call to the method session_start(), the variable $_SESSION is not going to be fulfilled.
Except: If in your php.ini you have set the option session.auto_start to 1, then, in that case it is not needed to call the session_start() because the variable $_SESSION is fulfilled implicitly.
You need to move session start/resume into your Session's constructor.
Like so:
class session{ function __construct() { if (! session_id()) { session_start(); } }
Another thing to mention, every time you'll do new Session
you'll be getting an object of the same functionality working with same global variable $_SESSION
.
You don't need more than one $session
object, it would be a good time to look into Singleton pattern
.