Reply to Re: How to figure out if a page has already been loaded

Your name:

Reply:


Posted by Ray Paseur on 11/24/05 15:28

I just posted this somewhere else, but it may be relevant to your question:

I use sessions all the time - one of my key functions prevents duplicate
submissions of form data. Here is a sample of my code:

All scripts begin with this:

<?php require_once('zz_universal_functions.php'); // COLLECTION OF FUNCTIONS
AND SESSION START
---

The "zz_universal_functions" contains, as its name implies, a lot of
functions relevant to the scripts, and ends with function and the "session
start" BEFORE ANY OUTPUT to the browser, including whitespace, blanks lines,
etc. Here is the tail end of my universal functions collection:

/* *************************************************************************
*/
function multi_submit($type = "post") {
//
// returns true if the form has been submitted with exactly this data, but
not processed
// if ( multi_submit() ) { // error processing } else { // normal
processing }
//
$string = "";
$input_array = ($type == "get") ? $_GET : $_POST;
foreach ($input_array as $val) { $string .= $val; }
$string = md5($string);

if ($_SESSION['_multi_submit'] === $string) {
return true;
} else {
$_SESSION['_multi_submit'] = $string;
return false;
}
}
/* *************************************************************************
*/
session_start(); // REQUIRED FOR FUNCTION MULTI_SUMBIT
?>
---

I also use cookies, sometimes in the same scripts that use sessions. They
work fine. Again, it is necessary to set or unset cookies before any output
to the browser. One mistake I have made with cookies is to unset the cookie
(using an historical expiration date) but forget to clear the element of the
$_COOKIE array. Later script logic got confused because it found stuff in
the $_COOKIE array, but the next page in the logic flow did not find the
cookie, etc... I watch out for that now!

~Ray

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация