Help on sessions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hemanth

    Help on sessions

    Hello there,

    A newbie question....any help is appreciated.

    I'm trying to create a script that searches a few database tables based
    on the search text and user search preferences. I created a PHP script
    (search_form.ph p) that displays textbox, a search button and a
    preferences link. The preferences link opens a popup (preferences.ht ml)
    and lists search categories (checkboxes - with search only in column1,
    column2 etc. or ALL) and a select button. If the users specify the
    preferences I call search_form.php with an "prefs[]" array as argument.
    In search_form.php I invoke another script (search.php) - to display
    search results - based on user preferences and search text entered.

    My question is, how do I make the script remember these preferences and
    search text (if user selects links like "Back to Search Results" or
    "Back to new search" in other pages) till he closes the existing
    window. I understand I can use PHP sessions to acheive this but I
    couldn't seem to make it work (probably I'm doing something wrong).
    =============== =============== =============== ==============
    I use the below code in each PHP script.
    <?php
    session_start() ;
    header("Cache-control: private");
    ?>

    Here's the code I use in "search_form.ph p"

    $fields = $_GET["prefs"]; //prefs array from "preferences.ht ml"

    //If preferences are not set by user AND session variable fields not
    set
    if(!isset($_SES SION['fields']) && !isset($fields) )
    $_SESSION['fields'] = array("all"); // use default option "ALL"
    else{
    //If session variable fields not set
    if(!isset($_SES SION['fields']))
    $_SESSION['fields'] = $fields; //else assign user preferences.
    }
    print_r($_SESSI ON['fields']); //PRINT options
    =============== =============== =============== =============== ==
    The problem is, whenever I call the "search_form.ph p" from a link (Back
    to New search) in search results page, the PRINT statement always
    displays "all" - the default option - I mean, the first if statement is
    always true. What could be the mistake in my code?

    TIA
    Singamsetty.

  • R. Rajesh Jeba Anbiah

    #2
    Re: Help on sessions

    Hemanth wrote:[color=blue]
    > I'm trying to create a script that searches a few database tables based
    > on the search text and user search preferences. I created a PHP script
    > (search_form.ph p) that displays textbox, a search button and a
    > preferences link. The preferences link opens a popup (preferences.ht ml)
    > and lists search categories (checkboxes - with search only in column1,
    > column2 etc. or ALL) and a select button. If the users specify the
    > preferences I call search_form.php with an "prefs[]" array as argument.
    > In search_form.php I invoke another script (search.php) - to display
    > search results - based on user preferences and search text entered.
    >
    > My question is, how do I make the script remember these preferences and
    > search text (if user selects links like "Back to Search Results" or
    > "Back to new search" in other pages) till he closes the existing
    > window. I understand I can use PHP sessions to acheive this but I[/color]
    <snip>

    FWIW, I would say that your design is not user friendly. What I
    would prefer is that the provision to store the Preferences in DB in
    separate page and in the search page again showing the "remembered
    preferences" so that the user can override previous preferences in the
    search page for the current search alone. Use of session for search
    will break usability, IMHO. This is what is I'm witnessing in mantis
    bts.

    --
    <?php echo 'Just another PHP saint'; ?>
    Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

    Comment

    Working...