How to transfer an array to another page via hidden form in php
Topics

--><!-- How to transfer an array to another page via hidden form-->

<h1>How to transfer an array to another page via hidden form in php</h1>

<?php

$variable = null;
$variable = array();
$variable [] = 'This variable can contain something.';
$variable [] = 'It can also contain more text.';
?>
<p>This is a variable printed with print_r</p>

<?php
print_r2($variable);
?>

<p>This is the serialized variable:</p>

<p>
<?php
$serialized=(serialize($variable));
$stripped = preg_replace("/\"/","&quot;",$serialized);
echo $stripped;
?>
</p>

<p>
The browser receives:
</p>

<img src="../images/entity_quote.png">

<p>
It is echoed with:
</p>

<pre>
$serialized=(serialize($variable));
$stripped = preg_replace("/\"/","&amp;quot;",$serialized);
echo $stripped;
</pre>





<p>
We replace the quotes with the corresponding entity.
<br><i>Serialize</i> means you make a long string of an object.
</p>

<form method="post" action="examples/transfer.php">
<input type="hidden" name="all_files" value="<?php echo $stripped; ?>">
<input type="submit" value="send it to transfer.php">
</form>

<p><i>transfer.php contains:</i></p>

<img src="../images/transfer.png" width="673" height="521" alt="" border="0">

<p>Why replace the quotes? Because if you don't, this will happen:</p>
<img src="../images/what_quotes_do.png" width="799" height="142" alt="" border="0">
<p>Only the turquoise value will be transferred (everything between the two quotes). </p>
<h3>Remember that hidden forms are never really hidden.</h3>
<p>If you right click into the browser window to show source, you will see the "hidden" form:</p>
<div class="long_image"><img src="../images/hidden-form.png" width="1465" height="98" alt="" border="0"></div>
<br>

<br>
<br>
<?php $Weblog->share ();?>

Sneak peek of the server side code