Help on sessions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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.php) that displays textbox, a search button and a
preferences link. The preferences link opens a popup (preferences.html)
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.
header("Cache-control: private");

Here's the code I use in "search_form.php"

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

//If preferences are not set by user AND session variable fields not
if(!isset($_SESSION['fields']) && !isset($fields))
    $_SESSION['fields'] = array("all");      // use default option "ALL"
    //If session variable fields not set
        $_SESSION['fields'] = $fields;           //else assign user preferences.
print_r($_SESSION['fields']);        //PRINT options
The problem is, whenever I call the "search_form.php" 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?


Re: Help on sessions

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Site Timeline