pass array between two php files

浪子不回头ぞ 提交于 2019-12-02 12:00:57

If you don't want to expose your $array, you MUST use PHP inbuild session support.

session_start(); // DO CALL ON TOP OF BOTH PAGES
$_SESSION['array'] = $array;
echo $_SESSION['array']; // GIVES SAME $array FOR BOTH PAGES
Halcyon

Use http_build_query:

header("Location: someurl.php?" . http_build_query($arr));

That's not how you do headers. it'd have to be

header("Location: someurl.php?vals=$arr");

however, this would just generat the URL

someurl.php?vals=Array

Note that a redirect by its nature cannot do a POST. it will result in a new GET request, meaning you have to pass data in the URL. If you have a very large url, you're almost guaranteed to lose most of it, as URLs have length limits.

However, if it's a short one, you can try something like:

$url = 'someurl.php?vals=' . url_encode(serialize($arr));
header("Location: $url");

and hope it works.

Juan Alberto López Cavallotti

You may store the array on the session or the request and then retrieve it.

If it is a different request you'll have to do it in the session.

$_SESSION['myarray'] = $array_you_want_to_store;

And then.

$array_you_want_to_retrieve = $_SESSION['myaarray'];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!