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

Hi!
I'm Karsten and I want to help people learn German.
Buy me a coffee if you feel I did well.

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

This is a variable printed with print_r

Array
(
    [0] => This variable can contain something.
    [1] => It can also contain more text.
)

This is the serialized variable:

a:2:{i:0;s:36:"This variable can contain something.";i:1;s:30:"It can also contain more text.";}

The browser receives:

It is echoed with:

$serialized=(serialize($variable));
$stripped = preg_replace("/\"/",""",$serialized);
echo $stripped;

We replace the quotes with the corresponding entity.
Serialize means you make a long string of an object.

transfer.php contains:

Why replace the quotes? Because if you don't, this will happen:

Only the turquoise value will be transferred (everything between the two quotes).

Remember that hidden forms are never really hidden.

If you right click into the browser window to show source, you will see the "hidden" form:




submit to reddit


Sneak peek of the server side code