0

I wish to pass an array through url. I checked at passing arrays as url parameter. Isnt there any other way? Below is my code

$result=Users.LoggedInUsers();
header('Location: http://localhost/Campus/Users.php?id='.$result.'');
Community
  • 1
  • 1
abc
  • 1
  • 1
  • 2
  • 3

2 Answers2

1

Check out http_build_query

example

<?php
$arr = array(1,2,3,4);
echo http_build_query(array('arr'=>$arr));
//arr%5B0%5D=1&arr%5B1%5D=2&arr%5B2%5D=3&arr%5B3%5D=4
mpen
  • 272,448
  • 266
  • 850
  • 1,236
0

You can serialize it easily, then unserialize it to get it back to an array:

$result=serialize(Users.LoggedInUsers());
header('Location: http://localhost/Campus/Users.php?id='.$result.'');
nickb
  • 59,313
  • 13
  • 108
  • 143
  • If you unserialize untrusted input from a URL, be certain to validate the entire contents of the array. – Michael Berkowski Mar 10 '12 at 02:18
  • It is showing following error Warning: Header may not contain more than a single header, new line detected on Users.php i did $booksArr = $_GET['id']; $result=unserialize(urldecode($booksArr)); – abc Mar 10 '12 at 02:20