0

I'm trying to create a PHP response script that redirects back to a target URL. unfortunately currently when I redirect, the JSON value is not send together. below code is what I've tried.

<?php
  header('Location: https://alia.com/readme.html');
  $data1 = array('a', 'b', 'c');
  header('Content-type: application/json');
  echo json_encode($data1);
  //prints json array ["a","b","c"]
?>

I wonder how can I create a php response and redirect back to client page.

ilse2005
  • 11,189
  • 5
  • 51
  • 75
Alia Ramli Ramli
  • 405
  • 6
  • 18
  • what does https://alia.com/readme.html do with a json, why aren't you posting to that url? – madalinivascu Mar 01 '16 at 09:35
  • That will send the json with it. I assume you misunderstood making POST requests? – Sbls Mar 01 '16 at 09:51
  • @Sbls the client will send post request to server, assume code above is try to response back to client request, i dont include the real logic and url. currently it only able to redirect to target url. but no json response tie together in the response. – Alia Ramli Ramli Mar 01 '16 at 10:11

1 Answers1

0
header('Content-type: application/json', true, 200);
$arrayResponse =array(
    'data'=> array('Ram','Pukar','Developer','PHP',"Java")
);
$encode = json_encode($arrayResponse);
print_r($encode);

Output:

enter image description here

Ram Pukar
  • 1,583
  • 15
  • 17