Re: [phplib] URLs and session variables (newbee) From: nathan r. hruby (nhruby <email protected>)
Date: 05/22/01

On Tue, 22 May 2001, Ninjaman wrote:

>
> I have some problems getting my head around how to create links that change
> session variables.
>
> I am trying to make an interface that changes depending on the "mode" I set
> it in. I am using phpLibs sessions and templates so far.
>
> A string to the template might look like this:
> $my_url = $sess->self_url();
> "<A href=\"$my_url?mode=result\">Klick here for a new mode</A>"
>
> I then have a switch structure that calls to different items to be displayed
> In different modes.
>
> The ?mode=result part is my attempt to make a self url chande a variable. I
> don't know if this is the way to go or not. And if so, I don't know how to
> make that variable a part of my session when the page reloads.
>
> I want self-pointing links that chande the session variable mode.
>
> Can anyone shed some light on this for me.
>

You can either GET them: http://www.foo.com/index.php?mode=someMode
and then in code do this
if ($HTTP_GET_VARS["mode"] = 'someMode') then {
   ...
} elseif ( ... ) {
   ...
}

or used a POST'ed form:
<form action="index.php">
<input type="submit" value="Some Mode 0" name="mode">
<input type="submit" value="Some Mode 1" name="mode">
<input type="submit" value="Some Mode 2" name="mode">
</form>

and in code do this:
if ($HTTP_POST_VARS["mode"] = 'Some Mode 1') then {
   ...
} elseif (...) {
   ...
}

Using forms with Session will result in the User getting "Data Has
Expired. Please hit Reload" messsages from their browser every time they
use the back button, so make sure your provide really good and obvious
navigation tools if you go this route. Not to say that It can't be done,
it's just harder, the payoff being that people get to push buttons,
instead of just clicking links.. different user experince, one closer to a
tradtional app running on their desktop. (Also this gets around having to
do the below for every link... :)

I do notice you are using Session::self_url() for creating the
href's you should be aware of the Session::add_query() method for adding q
GET query string to your url made with Session::self_url(). See:
http://phplib.netuse.de/documentation/documentation-3.html#ss3.8 for more
info but essentailly you want to do this:

$my_url = $sess->self_url() . $sess->add_query(array('mode' => 'modeVal'));

-n

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
nathan hruby / digital statement
nathan <email protected>
http://www.dstatement.com/

Public GPG key can be found at: http://www.dstatement.com/nathan-gpg-key.txt ED54 9A5E 132D BD01 9103 EEF3 E1B9 4738 EC90 801B -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>