Sample Header Ad - 728x90

Extracting a URL from a HTTP 200 Response and redirecting to that url

0 votes
2 answers
59 views
I've been searching for a while but I haven't found anything that 100% matches what I would like to achieve. I'm submitting data to an API and getting a response. I can see the submission is successful and I need to redirect to a url that's contained within the response. Example of the response...
{ "status": "OK", "redirectUrl": "https:\/\/blalabla.com" }
These are the things I've tried...
$decodedarray = json_decode($response,true);

if($decodedarray['status'] == "OK") {
	header("Location: ".$decodedarray['redirectUrl']);
}
if($response->response->header->status == 200)
	{
		$redirect_url = $result->response->body->redirectUrl;
		
		header("Location: ".$redirect_url);
		die();
	}
if($response->response->body->status == 200)
	{
		$redirect_url = $result->response->body->redirectUrl;
		
		header("Location: ".$redirect_url);
		die();
	}
The page looks like its refreshing after the submission and sometimes I see the response in the browser. But it won't automatically redirect to the given url. The url is dynamic and changes so I can't hard code it. I'd appreciate any pointers please. Thanks
Asked by Glen (3 rep)
Oct 2, 2024, 01:32 PM
Last activity: Oct 2, 2024, 08:24 PM