pass array between two php files

后端 未结 4 1022
失恋的感觉
失恋的感觉 2020-12-12 07:21

I have a php file that needs to redirect to another, but I need to pass an array to the second file. How can I do this.

I know this is wrong, but I need something l

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 08:03

    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.

提交回复
热议问题