Capturing $_REQUEST and reusing it later

This is a discussion on Capturing $_REQUEST and reusing it later within the PHP Language forums, part of the PHP Programming Forums category; I'm working on an authentication system in which it's possible that a user might be requested to log-...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2005
Geoff Soper
 
Posts: n/a
Default Capturing $_REQUEST and reusing it later

I'm working on an authentication system in which it's possible that a user
might be requested to log-in as a result of submitting a form if the
inactivity timeout is exceeded. In order that they don't lose the
information in the form I would like to capture this information ($_RESULT),
serialise it and store it in their session. After they've successfully
logged in I would like to retrieve this information and put it back in
$_RESULT so the user can carry on with what they were doing. Is $_RESULT
meant to be writable in this wayand is there any reason why this isn't a
good idea?

Thanks,
Geoff


Reply With Quote
  #2 (permalink)  
Old 01-09-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Capturing $_REQUEST and reusing it later

Geoff Soper wrote:
> I'm working on an authentication system in which it's possible that a

user
> might be requested to log-in as a result of submitting a form if the
> inactivity timeout is exceeded. In order that they don't lose the
> information in the form I would like to capture this information

($_RESULT),
> serialise it and store it in their session. After they've

successfully
> logged in I would like to retrieve this information and put it back

in
> $_RESULT so the user can carry on with what they were doing. Is

$_RESULT
> meant to be writable in this wayand is there any reason why this

isn't a
> good idea?


$_REQUEST is writable, but not "carryable" as session ($_SESSION).

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
  #3 (permalink)  
Old 01-09-2005
Roy W. Andersen
 
Posts: n/a
Default Re: Capturing $_REQUEST and reusing it later

Geoff Soper wrote:
> I'm working on an authentication system in which it's possible that a user
> might be requested to log-in as a result of submitting a form if the
> inactivity timeout is exceeded. In order that they don't lose the
> information in the form I would like to capture this information ($_RESULT),
> serialise it and store it in their session. After they've successfully
> logged in I would like to retrieve this information and put it back in
> $_RESULT so the user can carry on with what they were doing. Is $_RESULT
> meant to be writable in this wayand is there any reason why this isn't a
> good idea?


I assume by $_RESULT you mean $_REQUEST?

To store it:

foreach ($_REQUEST as $key=>$value) {
$_SESSION['REQUEST'][$key] = $value;
}

This will simply store all the $_REQUEST variables in the session as the
array $_SESSION['REQUEST']

Then to get it back:

foreach ($_SESSION['REQUEST'] as $key=>$value) {
$_REQUEST[$key] = $value;
}

Or, if they fail the login, destroy the array:
unset($_SESSION['REQUEST']);

If you don't want to store all the $_REQUEST vars but only some of them
you can just use a switch-statement before storing them.

foreach ($_REQUEST as $key=>$value) {
switch ($key) {
case "var_to_keep":
case "another_var_to_keep":
case "yet_another_var_to_keep":
$_SESSION['REQUEST'][$key] = $value;
break;
default:
break;
}
}

Just make sure you call session_start(); on the pages where you want to
use this, or the $_SESSION variables won't be carried over.

Hope that helps :)


Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Reply With Quote
  #4 (permalink)  
Old 01-09-2005
porneL
 
Posts: n/a
Default Re: Capturing $_REQUEST and reusing it later


> To store it:
>
> foreach ($_REQUEST as $key=>$value) {
> $_SESSION['REQUEST'][$key] = $value;
> }


Why not simply $_SESSION['REQUEST'] = $_REQUEST;?


--
* html {redirect-to: url(http://browsehappy.pl);}
Reply With Quote
  #5 (permalink)  
Old 01-09-2005
Roy W. Andersen
 
Posts: n/a
Default Re: Capturing $_REQUEST and reusing it later

porneL wrote:
>
>> To store it:
>>
>> foreach ($_REQUEST as $key=>$value) {
>> $_SESSION['REQUEST'][$key] = $value;
>> }

>
>
> Why not simply $_SESSION['REQUEST'] = $_REQUEST;?


Why not indeed? :)

I put the switch-statement in that loop when I started writing the post,
and decided to put it up as an alternative afterwards instead, and left
the loop as it was.


Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0