maintaining state with sessions - help

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

    #1

    maintaining state with sessions - help

    Probably a newbie question about "state":

    My problem is I have a search form, so user enters a keyword <enter>,
    then this form posts to another page were the result are displayed. But
    this display page uses pagination to break the results up into several
    subsequent pages. The 1st page is OK, but 2nd...last display pages loose
    the key word variable I initially posted.

    Seems I could keep passing the keyword with GET, I already use
    GET to pass pager info. Or I could try a SESSION way. I'd prefer
    not to use cookies.

    Ques 1.
    How do I pass more than one (say two in this case) variables
    to a new page with GET. right nowfor the pager I have eg.
    echo "<a href=\"search_t est2.php?page=$ i\">Page $i</a>";
    How would I stick $key_word in there to also pass it on to
    the next page? Then at the target page I have now:
    $page = $_GET['page'];
    So do I just add: $key_word = $_GET['keyword'];
    Just snippets would help w/syntax.

    Ques 2.
    I also want to try a SESSION way to maintain state. Again, I have
    a building block but not sure of syntax. How do I conbine the two
    blocks below so it will work. I want to maintain state of the user's
    input keyword. Not sure how combine the html and the php below.
    Thanks.


    <?php
    session_start() ; // start session
    $_SESSION['keyword'] = 'key_word';
    ?>

    <form action="search_ test2.php" method="post">
    <p>Your key word: <input type="text" name="key_word" /></p>
    <p><input type="submit" /></p>
    </form>
  • steve

    #2
    Re: maintaining state with sessions - help

    "leegold2" wrote:[color=blue]
    > Probably a newbie question about "state":
    >
    > My problem is I have a search form, so user enters a keyword
    > <enter>,
    > then this form posts to another page were the result are displayed.
    > But
    > this display page uses pagination to break the results up into[/color]
    several[color=blue]
    >
    > subsequent pages. The 1st page is OK, but 2nd...last display pages
    > loose
    > the key word variable I initially posted.
    >
    > Seems I could keep passing the keyword with GET, I already use
    > GET to pass pager info. Or I could try a SESSION way. I’d prefer
    > not to use cookies.
    >
    > Ques 1.
    > How do I pass more than one (say two in this case) variables
    > to a new page with GET. right nowfor the pager I have eg.
    > echo "<a href=\"search_t est2.php?page=$ i\">Page $i</a>";
    > How would I stick $key_word in there to also pass it on to
    > the next page? Then at the target page I have now:
    > $page = $_GET[’page’];
    > So do I just add: $key_word = $_GET[’keyword’];
    > Just snippets would help w/syntax.
    >
    > Ques 2.
    > I also want to try a SESSION way to maintain state. Again, I have
    > a building block but not sure of syntax. How do I conbine the two
    > blocks below so it will work. I want to maintain state of the
    > user’s
    > input keyword. Not sure how combine the html and the php below.
    > Thanks.
    >
    >
    > <?php
    > session_start() ; // start session
    > $_SESSION[’keyword’] = ’key_word’;
    > ?>
    >
    > [back-arrow]form action="search_ test2.php" method="post">
    > <p>Your key word: <input type="text" name="key_word"
    > /></p>
    > <p><input type="submit" /></p>
    > </form>[/color]

    Leegold,
    In this particular case, don’t use sessions. Why? because, lets say
    the user is conducting multiple keyword searches at the same time.
    The session would cause the subsequent pages of search results to use
    the wrong keywords!
    You MUST use ’GET’ in this case, to be safe.

    to pass multiple variables, you pass them thru urlencode() and then
    attach them to the url. Then on the new page, you simply
    read the variable via "GET" and parse the keywords using space as
    the seperator.

    As far as Q2, I am not very clear. But you simply assign your
    keywords to the $_SESSION and read them
    on the subsequent pages. You have it right (but not recommended for
    keyword paging).

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-maintain...ict132921.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=443883

    Comment

    • leegold2

      #3
      Re: maintaining state with sessions - help

      steve wrote:[color=blue]
      > "leegold2" wrote:[color=green]
      > > Probably a newbie question about "state":
      > >
      > > My problem is I have a search form, so user enters a keyword
      > > <enter>,
      > > then this form posts to another page were the result are displayed.
      > > But
      > > this display page uses pagination to break the results up into[/color]
      > several[color=green]
      > >
      > > subsequent pages. The 1st page is OK, but 2nd...last display pages
      > > loose
      > > the key word variable I initially posted.
      > >
      > > Seems I could keep passing the keyword with GET, I already use
      > > GET to pass pager info. Or I could try a SESSION way. I’d prefer
      > > not to use cookies.
      > >
      > > Ques 1.
      > > How do I pass more than one (say two in this case) variables
      > > to a new page with GET. right nowfor the pager I have eg.
      > > echo "<a href=\"search_t est2.php?page=$ i\">Page $i</a>";
      > > How would I stick $key_word in there to also pass it on to
      > > the next page? Then at the target page I have now:
      > > $page = $_GET[’page’];
      > > So do I just add: $key_word = $_GET[’keyword’];
      > > Just snippets would help w/syntax.
      > >
      > > Ques 2.
      > > I also want to try a SESSION way to maintain state. Again, I have
      > > a building block but not sure of syntax. How do I conbine the two
      > > blocks below so it will work. I want to maintain state of the
      > > user’s
      > > input keyword. Not sure how combine the html and the php below.
      > > Thanks.
      > >
      > >
      > > <?php
      > > session_start() ; // start session
      > > $_SESSION[’keyword’] = ’key_word’;
      > > ?>
      > >
      > > [back-arrow]form action="search_ test2.php" method="post">
      > > <p>Your key word: <input type="text" name="key_word"
      > > /></p>
      > > <p><input type="submit" /></p>
      > > </form>[/color]
      >
      > Leegold,
      > In this particular case, don’t use sessions. Why? because, lets say
      > the user is conducting multiple keyword searches at the same time.
      > The session would cause the subsequent pages of search results to use
      > the wrong keywords!
      > You MUST use ’GET’ in this case, to be safe.
      >
      > to pass multiple variables, you pass them thru urlencode() and then
      > attach them to the url. Then on the new page, you simply
      > read the variable via "GET" and parse the keywords using space as
      > the seperator.[/color]

      It's a mess AFAIK because I'm trying Boolean FULLTEXT and
      I have to pass w/GET literally eg. '+high +altitude' and it's
      giving me strange results. If I got a form passing that w/GET
      what do I do?



      [color=blue]
      >
      > As far as Q2, I am not very clear. But you simply assign your
      > keywords to the $_SESSION and read them
      > on the subsequent pages. You have it right (but not recommended for
      > keyword paging).
      >[/color]

      Comment

      • leegold2

        #4
        Re: maintaining state with sessions - help

        leegold2 wrote:
        I'm starting a new thread cause i think I need rawurlencode()
        I'm getting strange results from my GET - imo I should start
        w/fresh ques/thread in this group.
        [color=blue]
        > steve wrote:
        >[color=green]
        >> "leegold2" wrote:[color=darkred]
        >> > Probably a newbie question about "state":
        >> > > My problem is I have a search form, so user enters a keyword
        >> > <enter>, > then this form posts to another page were the result[/color]
        >> are displayed.[color=darkred]
        >> > But > this display page uses pagination to break the results up into[/color]
        >> several[color=darkred]
        >> > > subsequent pages. The 1st page is OK, but 2nd...last display pages
        >> > loose > the key word variable I initially posted.
        >> > > Seems I could keep passing the keyword with GET, I already use
        >> > GET to pass pager info. Or I could try a SESSION way. I’d prefer
        >> > not to use cookies.
        >> > > Ques 1.
        >> > How do I pass more than one (say two in this case) variables
        >> > to a new page with GET. right nowfor the pager I have eg.
        >> > echo "<a href=\"search_t est2.php?page=$ i\">Page $i</a>";
        >> > How would I stick $key_word in there to also pass it on to
        >> > the next page? Then at the target page I have now:
        >> > $page = $_GET[’page’];
        >> > So do I just add: $key_word = $_GET[’keyword’];
        >> > Just snippets would help w/syntax.
        >> > > Ques 2.
        >> > I also want to try a SESSION way to maintain state. Again, I have
        >> > a building block but not sure of syntax. How do I conbine the two
        >> > blocks below so it will work. I want to maintain state of the
        >> > user’s
        >> > input keyword. Not sure how combine the html and the php below.
        >> > Thanks.
        >> > > > <?php
        >> > session_start() ; // start session
        >> > $_SESSION[’keyword’] = ’key_word’;
        >> > ?>
        >> > > [back-arrow]form action="search_ test2.php" method="post">
        >> > <p>Your key word: <input type="text" name="key_word"
        >> > /></p>
        >> > <p><input type="submit" /></p>
        >> > </form>[/color]
        >>
        >> Leegold,
        >> In this particular case, don’t use sessions. Why? because, lets say
        >> the user is conducting multiple keyword searches at the same time. The
        >> session would cause the subsequent pages of search results to use
        >> the wrong keywords!
        >> You MUST use ’GET’ in this case, to be safe.
        >>
        >> to pass multiple variables, you pass them thru urlencode() and then
        >> attach them to the url. Then on the new page, you simply
        >> read the variable via "GET" and parse the keywords using space as
        >> the seperator.[/color]
        >
        >
        > It's a mess AFAIK because I'm trying Boolean FULLTEXT and
        > I have to pass w/GET literally eg. '+high +altitude' and it's
        > giving me strange results. If I got a form passing that w/GET
        > what do I do?
        >
        >
        >
        >[color=green]
        >>
        >> As far as Q2, I am not very clear. But you simply assign your
        >> keywords to the $_SESSION and read them
        >> on the subsequent pages. You have it right (but not recommended for
        >> keyword paging).
        >>[/color][/color]

        Comment

        • steve

          #5
          Re: Re: maintaining state with sessions - help

          "leegold2" wrote:[color=blue]
          > steve wrote:[color=green]
          > > "leegold2" wrote:[/color]
          > ....
          > It’s a mess AFAIK because I’m trying Boolean FULLTEXT and
          > I have to pass w/GET literally eg. ’+high +altitude’ and
          > it’s
          > giving me strange results. If I got a form passing that w/GET
          > what do I do?
          >
          >
          >
          >[/color]
          Leegold, it should be relatively easy to do. So let’s say the user
          input
          $a = "high altitude" then you attach to url "&keywords= " .
          urlencode($a);
          You also pass the paging info, i.e. what page is the next page, e.g.
          you attache "&page=2" to the url. Now you are done.

          When the new page script is executing, you simply read
          $_GET[’keywords’] and it would be equal to "high altitude".

          --
          http://www.dbForumz.com/ This article was posted by author's request
          Articles individually checked for conformance to usenet standards
          Topic URL: http://www.dbForumz.com/PHP-maintain...ict132921.html
          Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=444087

          Comment

          • steve

            #6
            Re: Re: maintaining state with sessions - help

            "leegold2" wrote:[color=blue]
            > leegold2 wrote:
            > I’m starting a new thread cause i think I need rawurlencode()
            > I’m getting strange results from my GET - imo I should start
            > w/fresh ques/thread in this group.
            >[color=green][color=darkred]
            > >></font>[/color][/color][/color]

            Why don’t you set up two simple scripts, where one calls the other.
            Assign the keywords as we discussed, and see how it comes out in
            $_GET. Everyone is using this, so you don’t need any new functions.
            If you do simple scripts, then you can post them here, and we can help
            u.

            --
            http://www.dbForumz.com/ This article was posted by author's request
            Articles individually checked for conformance to usenet standards
            Topic URL: http://www.dbForumz.com/PHP-maintain...ict132921.html
            Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=444111

            Comment

            Working...