21. April 2011
von Blackbam

Today we have been searching for an easy and fast way to store and reuse $_POST variables over 2 pages and more without using a session. This can save you a lot of work in some cases. This possiblity is completly browser based, so there is no need for the server to re-identify a user.


Save $_POST or some other array to a hidden field by converting it to the JSON-format. Use URL-encode to make sure that there will be no encoding problems.


Decode the hidden-fields' value on the server-side. Replace the $_POST variables depending on your needs or take the new ones.


// We save previous POST values in the 'post_saver', to provide page navigation and so on
if(strlen($_POST['post_saver'])>0) {

	$previous_post_object = json_decode(urldecode($_POST['post_saver']));
	unset($_POST['post_saver']);
	
	foreach($previous_post_object as $pkey=>$pval) {
		if(strlen($_POST[$pkey]) <= 0) {
			$_POST[$pkey] = $pval;
		}
	}
}
Share

Dieser Eintrag wurde am 21. April 2011 um 22:22 in der Kategorie PHP, Web Development veröffentlicht. You can book the comments for this article RSS 2.0. Feedback, discussion, commendation and critics are welcome: Write a comment or trackback.


Tags: , , ,

Warning: Use of undefined constant Ext_related_links - assumed 'Ext_related_links' (this will throw an Error in a future version of PHP) in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php on line 75

No comments yet

Kommentare abonnieren (RSS) or URL Trackback

Leave a comment:

Warning: include_once(/home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache-premium/pro/library/lazy-load.php): failed to open stream: No such file or directory in /home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 763 Warning: include_once(): Failed opening '/home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache-premium/pro/library/lazy-load.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 763 Fatal error: Uncaught Error: Call to a member function lazy_load() on null in /home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache/inc/cache.php:766 Stack trace: #0 [internal function]: WpFastestCacheCreateCache->callback('...', 9) #1 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/functions.php(4469): ob_end_flush() #2 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/class-wp-hook.php(288): wp_ob_end_flush_all('') #3 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array) #4 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #5 /home/.sites/609/site1266/web/blackbams-blog/wp-includes/load.php(947): do_action('shutdown') #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /home/.sites/609/site1266/web/blackbams-blog/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 766