Search code examples
phphttpresponse.redirecthttp-status-code-200

PHP How to respond to HTTP Request and continue processing?


I am working with an API for a payment gateway that does a callback request. When the callback request is made, the gateway expects me to respond with "OK". Nothing more or less. And that doesn't mean html rendered response. Just a callback file with those 2 letters. Note that doesn't mean it wants HTTP Status Code 200/OK... it wants actual data (not headers) for the word "OK".

So this won't work:

<html><body>OK</body></html>

This will work:

<?php echo "OK"; ?>

however, after I send back OK, I need to do some stuff on the server side and then redirect the browser page to another page. But when I try to do:

<?php
echo "OK";
header('Location: http://www.store.com/success.php');
exit;
?>

The gateway ignores the echo "OK" and instead reads the html off of the success.php page that I redirect to.

So how can I send back just the OK but continue doing things on my side?

Thanks


Solution

  • You can't send content then redirect. The redirect header setting must be done alone.