#1
  1. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pembroke Pines, FL
    Posts
    11
    Rep Power
    0
    I have just tryed to use sessions but all I can see is a totally blank page , do you know why ? May be something wrong with the /tmp dir in php.ini ?
    Please help me , I have to do a shopping cart and I just started in the wrong way .
    This is the code :
    <?
    session_start();

    if (!$PHPSESSID) {
    session_register('body_color');
    session_register('text_color');

    } else if ((!$body_color) &#0124; &#0124; (!$text_color)) {

    session_register('body_color');
    session_register('text_color');

    }
    ?>

    Sergio.
  2. #2
  3. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pembroke Pines, FL
    Posts
    11
    Rep Power
    0
    The variable and the session is created in the /TMP directory but the page still look blank and the execution of the php page stop suddently when I declare a session ( es, session_start(); or Session_register(); ) .
    Please help me , I'm sure there is a lot of people interested in this....

    Sergio.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    1
    Rep Power
    0
    The code seems correct but a little bit redundant

    Try to consider this...

    "<?
    session_start(); ...
    "

    This call will load in memory the content of the current session, or will create a new one if no session is currently in use.
    If your browser has already send a sessionId along with the request, then all variables stored in the session will be available.
    Hence

    "if (!$PHPSESSID) {
    session_register('body_color');
    session_register('text_color');

    }
    "

    will not be executed even if a new session is established, due to first access to the resource ($PHPSESSID is always set).

    Furthermore

    "else if ((!$body_color) | | (!$text_color)) {

    session_register('body_color');
    session_register('text_color');

    }
    ?>
    "

    is executed only on the first access to the resource, when no variable named 'body_color' or 'text_color' is in scope. The second time (do you mean that you use the same resource to test session? it seems ...) the resource is get from the same browser instance, the session_register() call will bring in scope
    'body_color' and 'text_color', so the "if" part of "else" branch wil not be executed. Maybe this is the correct place where you will initialize those session variables.

    Try this
    "
    <?
    session_register('body_color');
    session_register('text_color');

    if ((!$body_color) | | (!$text_color)) {

    $body_color=$somecolor1; // you will assign
    // a color value here
    $text_color=$somecolor2; // you will assign
    // a color value here

    }

    // set body and text color to the values in
    //$body_color and $text_color

    ....
    ?>
    "
    Note that session_register() calls
    session_start().

    I don't know your session expiration settings. Maybe something is wrong with the session expiration. The default value is 0 meaning that session wil expire when the browser instance will be closed.

    Try to edit the session file in /tmp dir in order to verify correct value for session variables and verify that only one file is created. If more that one file is created then more than one session is spawned between two request.

    Hope will help

    PS: sorry if same error is included ... I have a little experience.

    Ciao Ugo.

  6. #4
  7. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pembroke Pines, FL
    Posts
    11
    Rep Power
    0
    Ok , thx a lot , I'll try it.
    (Non mi dire che sei italiano perchè ci potremmo risparmiare una fatica grandissima....almeno questo da parte mia.. )

    Sergio.

Similar Threads

  1. Replies: 245
    Last Post: February 8th, 2004, 01:10 PM
  2. Help needed with PHP4 sessions and arrays
    By mgnetuk in forum PHP Development
    Replies: 1
    Last Post: November 20th, 2003, 01:24 PM
  3. Couch Sessions
    By guest in forum Development Articles
    Replies: 58
    Last Post: May 28th, 2003, 09:05 AM
  4. URLs for good articles on sessions
    By true2u1 in forum PHP Development
    Replies: 3
    Last Post: January 9th, 2002, 06:44 AM
  5. Replies: 2
    Last Post: August 23rd, 2001, 08:32 PM

IMN logo majestic logo threadwatch logo seochat tools logo