SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP sessions issue

    Hi:

    It's been ages since I last used sessions but for the life of me I can't figure out what's wrong with my code.

    I have a db generated list of contacts with checkboxes. The list is paginated with prev->next links and the idea is to save the unique ids of each checkbox (taken from the PK in the DB) from the query string into a session for access across multiple pages.

    search.php does the searching and displaying and here's where I pick up and store the ids into a session:

    PHP Code:
    <?php
    session_start
    ();
    // search.php
    // search code goes here
    // save ids from $_GET data here:
    // Build array of checkbox values for this paginated page, serialize() &
    // pass via query string:
    $array_checked_ids explode(";",$_GET['id']);
    $encde_checked_ids base64_encode(gzcompress(serialize($array_checked_ids)));
    $sesh_name "chkd{$data['ID']}";
    if(isset(
    $_SESSION[$sesh_name]))
    {
        
    $_SESSION[$sesh_name] .= $array_checked_ids;
    }
    else
    {
        
    $_SESSION[$sesh_name] = $encde_checked_ids;
    }
    The subsequent page is where I want to access the ids for download - so in download.php:

    PHP Code:
    <?php
    // download.php
    session_start();
    // Dump the desired ids:
    $sesh_name "chkd{$data['ID']}";
    $checked unserialize(gzuncompress(base64_decode($_SESSION[$sesh_name])));
    var_dump($checked);
    When I go to download.php it only ever spits out the latest 50 ids (The number of results per paginated screen) I can never get it to "build" upon itself with the values from each preceeding screen.

    What am I doing wrong?
    Thanks a lot for any pointers

  2. #2
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session problem - continued

    Ok - I'm still struggling with the same problem and I've tried a bunch of other things too:

    Latest Code in search.php:
    PHP Code:
    <?php
    session_start
    ();
    header("Cache-control: private"); //IE 6 Fix 
    // search code here:

    $array_checked_ids explode(";",$_GET['plc_js_id']);
    $encde_checked_ids base64_encode(gzcompress(serialize($array_checked_ids)));
    $sesh_name "chkd{$data['ID']}";
    $sesh_data "";
    if(!isset(
    $_SESSION[$sesh_name]))
    {
    // Start a new session and make its value that of the encoded ids:
    $_SESSION[$sesh_name] = $encde_checked_ids;
    }
    else
    {
    // If a session already exists append its value to the current encoded list of ids:
    $sesh_data $encde_checked_ids.$_SESSION[$sesh_name];
    // Unset old session and re-establish with new value of $encde_checked_ids (above):
    unset($_SESSION[$sesh_name]);
    $_SESSION[$sesh_name] = false;
    session_destroy();
    session_start();
    header("Cache-control: private"); //IE 6 Fix 
    // Re-register session of the same name with new data set above:
    $_SESSION[$sesh_name] = $sesh_data;
    }
    ?>
    and in the page I wish to retrieve the ids called download.php:

    PHP Code:
    <?php
    session_start
    ();
    header("Cache-control: private"); //IE 6 Fix 
    $sesh_name "chkd{$data['ID']}";
    $checked $_SESSION[$sesh_name];
    $checked unserialize(gzuncompress(base64_decode($checked)));
    var_dump($checked);
    ?>
    It still only dumps the latest 50 ids.... I need another set of eyes....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •