Results 1 to 5 of 5
  1. #1
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Session Dropping
    I have a search form that goes to search.php?page=1 (has pagination). At the top of search.php I have:

    PHP Code:
    <?
    session_start
    ();
    $_SESSION['keyword'] = $_POST["keyword"];
    ?>
    Further in my code I explode $_SESSION['keyword'] (to alter the terms for boolean search), implode the terms and pass them off to my MySQL query. This all works, it returns the first page of results. Yet when I click the next page (search.php?page=2) it returns nothing, the session variable no longer exists.

    Any ideas as to why this is happening? I'm not super great with sessions, but something simple like this should work. I've passed simple session variables before, and across multiple pages even.

    Shawn Kerr (.com) | Disney World | SEC Football

  2. #2
    Member RWorld's Avatar
    Join Date
    December 18th, 2005
    Posts
    101
    If you are setting the SESSION values to the POST values each time, make sure the POST values are actually set - if they are not, your SESSION values will be subsequently cleared.

    try something like:
    if(isset($_POST['myvar'])) $_SESSION['myvar']=$_POST['myvar']

    for example
    <font size="1"><strong>[URL=http://www.thechesszone.com]TheChessZone[/URL]</strong> Chess sets and supplies.<br><strong>[URL=http://www.shareasale.com/shareasale.cfm?merchantID=9515]Join our affiliate program[/URL]</strong> Up to 12% commission!

  3. #3
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Well, I figured out I was going about it the wrong way anyway. I was trying to recapture what I had already posted and altered for the boolean search. So had it worked, I would have resubmitted the boolean search to be altered for boolean search another time.

    But I realized just a few minutes ago that once the script terminates I lose my keywords altogether.

    PHP Code:
    $keys explode(" "$_POST['keyword']); //back to original code w/o sessions
       
    foreach ($keys as $newkey) {
    $var[] = "+$newkey";
    }
    $newkeys implode(" "$var);

    // $newkeys is now +keyword1 +keyword2 etc.

    // mysql [fulltext] query with $newkeys works

    // print results just fine

    echo $newkeys// empty, well actually just + 
    So I need to figure out how to keep $newkeys alive period, but through the pagination.

    Shawn Kerr (.com) | Disney World | SEC Football

  4. #4
    Member RWorld's Avatar
    Join Date
    December 18th, 2005
    Posts
    101
    There are generally 3 ways to persist data in a stateless web app -
    1) Use sessions and pass the session ID in the URL or store it client side, so the session (and its contents) can be recreated at the start of each script

    2) Pass the data in the URL as parameters (and retrieve with $_GET)

    3) Pass the data as hidden (or not) form fields (and retrieve with $_POST)

    As it appears you have abandoned the session approach (don't know why, it would be the best IMO), you will need to pass whatever data you need to persist across multiple page calls as URL parameters, or in fields that are POSTed as required.
    <font size="1"><strong>[URL=http://www.thechesszone.com]TheChessZone[/URL]</strong> Chess sets and supplies.<br><strong>[URL=http://www.shareasale.com/shareasale.cfm?merchantID=9515]Join our affiliate program[/URL]</strong> Up to 12% commission!

  5. #5
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Quote Originally Posted by RWorld
    2) Pass the data in the URL as parameters (and retrieve with $_GET)
    Yeah, that's the easiest way. I was avoiding it, it makes me nervous.

    Quote Originally Posted by RWorld
    As it appears you have abandoned the session approach (don't know why, it would be the best IMO)
    Well, I'm losing my keywords variable ($newkeys) right off the bat as soon as the first page prints. Not sure why. So there's nothing to attach to a session variable anyway.

    I'll probably just end up passing it all through the URL. That's the route I should've gone in the first place and I'd have been done long ago.

    Shawn Kerr (.com) | Disney World | SEC Football

  6. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. ABW session at Summit
    By Sue in forum Events and Gatherings
    Replies: 47
    Last Post: March 10th, 2008, 02:58 PM
  2. merchant session cookie
    By Roland in forum Commission Junction - CJ
    Replies: 2
    Last Post: January 27th, 2006, 03:20 AM
  3. is a Session Cookie the way to go...
    By mooodyman in forum Newbie Affiliate FAQs & Helpful Articles
    Replies: 1
    Last Post: April 11th, 2005, 02:53 AM
  4. Magazine Q+A Session - 9/19/2004 @ 7:00 PM
    By Andy Rodriguez in forum Andy Rodriguez Consulting
    Replies: 1
    Last Post: September 19th, 2004, 11:22 AM

Posting Permissions

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