RE: [PHP] why values not remembered by php?
| From: | Sonia Tsui | Date: | Wed, 23 Aug 2000 02:13:42 +0000 |
| Subject: | RE: [PHP] why values not remembered by php? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13062@lists.php.net to get a copy of this message | ||
Lars,
Thank you very much for your explantion. It clears up my concept.
It works to encode vars into URL. But I am concerned about the security
because user can just change the values there on their browser. A better way
to do it, I think, is through hidden variables in a form.
As I understand, form is posted when yuo click submit button. My page
doesn't need to use form (because there is nothing to submit). So I don't
know how to make server remember the values through hidden variables in my
case. I hope I am not talking too unclear.
---Sonia
-----Original Message-----
From: Lars Torben Wilson [mailto:torben@pinc.com]
Sent: Tuesday, August 22, 2000 5:31 PM
To: Sonia Tsui
Cc: 'php-general@lists.php.net'
Subject: Re: [PHP] why values not remembered by php?
Sonia Tsui writes:
>
> Here is the sample code
> (main.php)
>
> <?php
> $start = $end;
> $end = $start + 3;
> ?>
>
> <html>
> ......
> <a href ="main.php" ....>nextbutton</a>
> <?php
> for ($i = $start; $i<$end; $i++) {
> echo("i: $i<br>");
> }
> ?>
> </html>
>
> -------------------------------------------------------------------------
> so when <next button> is pressed, it comes back to this page. What I don't
> understand is why $end is not remembered? I though variable exist for one
> http transaction. I expect to see 0, 1, 2, 3 and then 4, 5, 6 etc. but I
> just see 0,1,2,3 and then 0,1,2,3 again and again. Can anyone help with my
> simple question?
>
> ---Sonia
Exactly--variables exist only for the duration of the HTTP
transaction. That's one page view. Since HTTP is a stateless protocol,
the transaction goes something like this (simplified):
1) the browser opens a connection to the server
2) the browser requests a page
3) the server looks for the page, reads it, feeds it to PHP, and
sends the result back to the browser
4) the connection is closed
All variables are lost between pages, since there each page view
constitutes a brand new connection. Broadly speaking, the act of
working around this is called 'session management', meaning that you
somehow get the server to 'remember' variables between pages. You can
do this in a number of ways: for what you're doing here, the easiest
would probably be to encode the variables into an URL or stick them
into hidden variables, and then check them on the next page view.
More robust session management would typically involve the server
saving the variables somewhere, and then reloading them when the
viewer loads the next page. Often, cookies or URL variables are used
to keep track of what saved data belongs to which viewer. If you're
using PHP3, check out PHPLIB (http://phplib.netuse.de), which offers
this as well as a pile of other functionality. If you're using PHP4,
check out the session management functions at
http://www.php.net/manual/ref.session.php,
which also goes into a bit
more depth about what sessions actually are.
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net