more session...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

more session...

Post by 9902468 »

This might be a bit easy question, but how can I check if session is already started? I tried like this:

Code: Select all

session_start()
if ( isset ( $_SESSIONї"some_value"] ) ) {
         /* variable is set -> session is already started */
  }
  else {
 /* variable not found -> must start new session */
        unset($_SESSION);
        session_destroy();
  }
OK, all good, but if session is not started I must stop that session and check users password and username, and then, if passwd && username are correct, I start new session and set
$_SESSION["some_value"] = something, but obviously I get error msg: cannot set cache... headers already sent... (headers went to the tube while checking....)

Any checking methodes that comes in your mind?

Thanks
-9902468

--Note!! According to php documentation ob_start doesn't work....:
void ob_start ( [string output_callback])

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

why do you have to destroy the session at this state?
if isset ($_SESSION["some_value"]) is false, ok, the current user isn't in. Just check the login/password again and if successful store the new value in $_SESSION.
I would destroy the session only if a logged in user logged out manually.
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

Yeah, I guess you are right, but I should delete session also if password / username don't match.
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

9902468 wrote:but I should delete session also if password / username don't match.
i don't think you'd necessarily have to... can't it be safely assumed that if a login is attempted and failed, that it will be immediately retried (hence, overwriting the data with the new attempt)?
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

will wrote: i don't think you'd necessarily have to... can't it be safely assumed that if a login is attempted and failed, that it will be immediately retried (hence, overwriting the data with the new attempt)?
mmmmm. right.
Post Reply