By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

maintaining state with sessions - help

P: n/a
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_test2.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>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"leegold2" wrote:
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_test2.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>


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
Jul 17 '05 #2

P: n/a
steve wrote:
"leegold2" wrote:
> 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_test2.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>


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.


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?


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).

Jul 17 '05 #3

P: n/a
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.
steve wrote:
"leegold2" wrote:
> 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_test2.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>


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.

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?


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).

Jul 17 '05 #4

P: n/a
"leegold2" wrote:
steve wrote:
"leegold2" wrote:

....
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?

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
Jul 17 '05 #5

P: n/a
"leegold2" wrote:
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.
</font>


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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.