Re: [PHP-DB] Session Broken

2001-11-08 Thread Paul DuBois

At 9:25 AM + 11/8/01, Russ Michell wrote:
1: Rid any whitespace between '?php' and 'session_start()'
2: You need to populate the variable you wish to use as a session 
variable before registering it

Is 2 actually true?  The sessions chapter in the PHP manual doesn't seem
to specify any order for using and registering, and in fact gives examples
to the contrary (see examples 2 and 3 in the chapter).


?php
session_start();
if(!isset($UserName)){
$UserName = guest;
session_register('UserName');
}

//rest of script goes here
?

HTH
Russ

On Wed, 7 Nov 2001 20:02:03 -0500 Matthew Tedder [EMAIL PROTECTED] wrote:


  Can anyone tell me why my session isn't working?  I have attached 
the problem
  script.  Without even going to another page, the $PHPSESSID and $UserName
  variables are both empty.  They are also empty on subsequent pages. 

  It starts with:
  =
  ?php

  session_start();
  session_register(UserName);

  /*= Check for New User Session =*/
  if(!isset($UserName))
  {
$UserName = guest;
  };
  ==

  And toward the end, it has the following:
  ==
  function ShowMessage($message)
  {
print br\n;
print table border=2 align=center\n;
print trtd align=centerfont color=yellow$UserName ($PHPSESSID):
  $message/font/td/tr\n;
print /table\n;
  }

  ?
  ==

  In this function, the variables are flat empty.
  
   --Matthew


#---#

   Believe nothing - consider everything

   Russ Michell
   Anglia Polytechnic University Webteam
   Room 1C 'The Eastings' East Road, Cambridge

   e: [EMAIL PROTECTED]
   w: www.apu.ac.uk/webteam

   www.theruss.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Session Broken

2001-11-08 Thread Kodrik

 1: Rid any whitespace between '?php' and 'session_start()'

That makes no difference as long as you are not producing any output.
You can have spaces and code withing the php brackets, just not echo anything.
But don't have any spaces prior to ?php since it will be echoing a character.
The reason is that you are setting a cookie and making a header call.

 2: You need to populate the variable you wish to use as a session
 variable before registering it

I don't agree with that either

  Without even going to another page, the $PHPSESSID and
 $UserName variables are both empty.  They are also empty on subsequent
 pages.

If you don't leave the page and your variable is empty, that means it in 
empty within PHP in the first place. 
The variable within the session will not be retrieved until you hit the next 
page.

Your PHPSESSID will be also empty because it is the value that get 
transferred to another page.If you didn't transfer yet, you will not have a 
value.
If you want your session id, do:

$sessid=sessionid();

Also, be careful about the scope of your cookies.
A session is transfered through cookies in php (if available) and if you 
don't set your scope right, your session can be lost from one folder to 
another.

That brings me to a MySQL question for knowledgeable people:
I don't use php sessions but a custom session that is stored in a simple 
tables. I just transfer the a variable which holds the id to my session 
(which is a primary auto-increment int) that points to a row which holds all 
the information I need about the user.
Is it smart or is it a total waste of resources and I should stick with php 
built in support for sessions?
So far, I never experienced any problems with it.




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]