Jump to content

Session Variables - Is there a smarter way to do this?


Recommended Posts

Im passing form values over to a confirmation page where Im setting session variables in order to allow the user to "go back" if they wish, to ammend their previous entries.

 

I just wanted to ask....this seems very cumbersome. Is there a smarter way to do this? Because I have about 50 values from the form.

$_SESSION['share_header'] = isset($_REQUEST["share_header"]) ? $_REQUEST["share_header"] : "";
$_SESSION['share_rent'] = isset($_REQUEST["share_rent"]) ? $_REQUEST["share_rent"] : "";
$_SESSION['share_bond'] = isset($_REQUEST["share_bond"]) ? $_REQUEST["share_bond"] : "";
$_SESSION['share_proptype'] = isset($_REQUEST["share_proptype"]) ? $_REQUEST["share_proptype"] : "";
$_SESSION['theDate'] = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
$_SESSION['share_num'] = isset($_REQUEST["share_num"]) ? $_REQUEST["share_num"] : "";
$_SESSION['share_street'] = isset($_REQUEST["share_street"]) ? $_REQUEST["share_street"] : "";
$_SESSION['share_location'] = isset($_REQUEST["search"]) ? $_REQUEST["search"] : "";
$_SESSION['share_description'] = isset($_REQUEST["share_description"]) ? $_REQUEST["share_description"] : "";

Then don't store those fields in the session, simple as that.  $_POST is an array.  Using countless techniques, you can filter out what you do not want.

 

The best strategy? Blacklists and Whitelists.

 

If you have more fields that you need to save than you do the fields you don't want to save, then create a blacklist for those you want to avoid storing

If you have more fields that you do not need to save than you do fields you want to save, then create a whitelist for those you do indeed want to store.

 

I'm not exactly sure how you're data look, so I can't exactly write out a blacklist/whitelist ad-hoc script for you.  Programming is a logic game, play it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.