Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How can we know that a session is started or not?

Answers were Sorted based on User's Feedback



How can we know that a session is started or not?..

Answer / tushar

if(session_id()=="")
then we can say session is not started
otherwise
yes

Is This Answer Correct ?    9 Yes 0 No

How can we know that a session is started or not?..

Answer / sunil

is session_id returns as empty string, then there is no
current session.

Is This Answer Correct ?    3 Yes 0 No

How can we know that a session is started or not?..

Answer / sherin

session_id() returns the session id for the current session
or the empty string ("") if there is no current session.

Is This Answer Correct ?    2 Yes 0 No

How can we know that a session is started or not?..

Answer / ann

Session_start()

Is This Answer Correct ?    6 Yes 6 No

How can we know that a session is started or not?..

Answer / binay kumar

if(session_id()=="") session_start();

Is This Answer Correct ?    1 Yes 1 No

How can we know that a session is started or not?..

Answer / rakesh kumar nautiyal

Generally speaking I agree with what your saying about
needing to know
if a session has been started or not. But I also believe
it has its
place for some user land custom session handlers. Being
able to throw
an exception in a session object's __construct() or __wakeup
() for
various reasons can present a situation that is easily
solved inside
__construct() by:

if(session_has_started()) { // Added function via
patch
session_regenerate_id($newID); // Added $newID via
the patch
$_SESSION = array();
} else {
session_id($newID);
session_start();
}

Say there is an authentication token in the session, the
session needs
to be started so we can access the token. If the token
proves to be
invalid, we need to create a blank session with a new
session ID.

> Also, the concept of session_id_exists is
fundamentally
> broken (think of atomic file creation). That is why
there is
> no such function.

I disagree. If a provided session ID via $_REQUEST(for
arguments sake)
is found not to exist by using the theoretical
session_id_exists().
That would mean the script was given an ID that wasn't
created by PHP,
and the script logic could act accordingly. What am I
overlooking?

> Regarding providing an id to session_regenerate_id: I
have
> seen too many supposedly save session id generators
that I
> would be in favor of adding that kind of overwriting
power.

I agree that PHP should be left to create a unique ID. But
the
functionality currently exists for the user to set their
own ID with
session_id($newID). The user has this ability before a
session is
started. But loses the ability when trying to use
session_regenerate_id() in a similar fashion after the
session has
started. It seems like a contradiction to allow it in one
case and not
the other.

I could try and grok the source to figure it out myself,
but someone
here might know off the top of their head. Is calling
something like
md5(uniqid(rand(), TRUE)) better, worse, or equivalent to
how PHP
creates a unique session ID?

Is This Answer Correct ?    1 Yes 3 No

How can we know that a session is started or not?..

Answer / balaphp

session_start()

Is This Answer Correct ?    0 Yes 2 No

How can we know that a session is started or not?..

Answer / rohit darya ganj

If you want to know that session is started or not so print
out any session variable.

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More PHP Interview Questions

How do you trim spaces in excel?

0 Answers  


hai, friend i srinu i had completed my graduation in 2004. now i am fineshed PHP course .may i get any oppartunity on php progr pls sugg me . thank u

0 Answers  


Explain the purpose of output buffering in php.

0 Answers  


What are string functions?

0 Answers  


When to use self over $this?

0 Answers  


Explain the visibility of the property or method?

0 Answers  


What is meant by PEAR in PHP?

0 Answers  


What new features php7 has in store for us?

0 Answers  


What are magic constants in php?

0 Answers  


How many columns can be added in a table in mysql?

0 Answers  


How to register a variable in PHP session?

0 Answers  


if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer

0 Answers   Yash Technologies,


Categories