简体   繁体   中英

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

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

You could try using flush(); to force php to write out the OK.

使用javascript或meta refresh标签将重定向移动到客户端是否可以接受?

在发送“ OK之前,您可以通过命令行调用PHP,以使PHP表现为多重威胁。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM