Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP sessions that have already been started [duplicate]

Tags:

php

session

In my PHP code, if a session has already started, and I try to start a new one, I get the following Notice:

Notice: A session had already been started - ignoring session_start()

How can I avoid this?

like image 780
user1400702 Avatar asked May 18 '12 08:05

user1400702


People also ask

Can we start 2 sessions in PHP?

The answer is "no". You cannot start multiple sessions simultaneously. And if you do, you'll get an error like "A session had already been started". You don't need to start simultaneous sessions, so long you can create multiple keys.

Which of the following is used to check if session variable is already set or not in PHP?

Make use of isset() function to check if session variable is already set or not.

Where should a session start () function appear?

Unless you have output buffering enabled, the session_start() must come before anything other than headers are sent to the browser (as it sets a cookie in the header). It must come before you attempt to reference the $_SESSION data.


1 Answers

Try

<?php     if(!isset($_SESSION))      {          session_start();      }  ?> 
like image 102
Valeriy Gorbatikov Avatar answered Sep 27 '22 19:09

Valeriy Gorbatikov