Passing arrays as url parameter

前端 未结 10 1755
礼貌的吻别
礼貌的吻别 2020-11-22 12:32

What is the best way that I can pass an array as a url parameter? I was thinking if this is possible:

$aValues = array();

$url = \'http://www.example.com?a         


        
10条回答
  •  情歌与酒
    2020-11-22 12:50

    Easiest way would be to use the serialize function.

    It serializes any variable for storage or transfer. You can read about it in the php manual - serialize

    The variable can be restored by using unserialize

    So in the passing to the URL you use:

    $url = urlencode(serialize($array))

    and to restore the variable you use

    $var = unserialize(urldecode($_GET['array']))

    Be careful here though. The maximum size of a GET request is limited to 4k, which you can easily exceed by passing arrays in a URL.

    Also, its really not quite the safest way to pass data! You should probably look into using sessions instead.

提交回复
热议问题