What are the potential issues with passing an array using a Header-Location in PHP?
Passing an array using a Header-Location in PHP can lead to issues because the header function expects a string as its parameter. To solve this issue, you can serialize the array into a string before passing it in the header function, and then unserialize it on the redirected page to retrieve the original array.
$data = array('key1' => 'value1', 'key2' => 'value2');
$serialized_data = serialize($data);
header("Location: redirected_page.php?data=" . urlencode($serialized_data));
```
On the redirected page:
```php
$serialized_data = urldecode($_GET['data']);
$data = unserialize($serialized_data);
print_r($data);
Keywords
Related Questions
- What are the potential pitfalls of using DISTINCT in a MySQL query when displaying results in PHP?
- What are the potential pitfalls of not validating data, such as checking if an ID exists in the database?
- How can the Post/Redirect/Get pattern be implemented in PHP to improve user experience and prevent form resubmission issues?