Re: Passing Arrays between pages
| From: | Josh Whiting | Date: | Wed, 23 Mar 2005 02:39:18 +0000 |
| Subject: | Re: Passing Arrays between pages | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-211348@lists.php.net to get a copy of this message | ||
> >Please can someone tell me how you pass arrays between PHP pages.
>
> $var = serialize($testArray);
> echo "<INPUT NAME = \"kcompany[]\" TYPE = \"hidden\"
> VALUE=\"$var\">";
>
> Then unserialize the variable on the receiving page.
To this you might also add an MD5 hash to check for authenticity,
depending on what you're doing with that incoming data that you're
unserializing (consider an client who sends you a serialized array that
you didn't intend). You'll also want to encode the serialized data with
htmlentities:
$serialized = serialize($testArray);
$hash = md5($serialized . "my secret phrase");
echo '<input type="hidden" name="serialized"
value="'.htmlentities($serialized).'">';
echo '<input type="hidden" name="hash"
value="'.$hash.'">';
then on the receiving end:
if ($_POST['hash'] != md5($_POST['serialized'] . "my secret phrase") {
// the hash doesn't match up, consider the data unusable
} else{
$testArray = unserialize($_POST['serialized']);
}
HTH
/jw