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.'');

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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.'');

2 Comments

If you unserialize untrusted input from a URL, be certain to validate the entire contents of the array.
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));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.