开发者

Receiving and handling a GET request in PHP

开发者 https://www.devze.com 2022-12-17 23:41 出处:网络
I\'m trying to replace RSS polling with PubSubHubbub on my site. I\'m able to use the subscriber library that google offers to send the subscription req开发者_JS百科uest. From the code it looks like i

I'm trying to replace RSS polling with PubSubHubbub on my site. I'm able to use the subscriber library that google offers to send the subscription req开发者_JS百科uest. From the code it looks like it sends a post request via cURL with the RSS URL and a callback URL.

So this is where I need some direction:

In order to complete the subscription request my callback URL has to receive a GET request and then echo back a value from the GET request along with a 200 response. How do I get the parameters from the GET request? Is the echo done again via cURL? If so what option should include the 200 response?


This very simple script should be a start:

  echo $_GET["request_name"];

this will output the GET parameter request_name and (implicitly) send a 200.

It's also a good idea to explicitly declare a content type before echoing, to prevent the default content type (usually "text/html") from kicking in:

header("Content-type: text/plain");

Note that when echoing external data, you may need to sanitize the output first - if the for example the output format is HTML, you would want to do something like echo htmlspecialchars($_GET["request_name"]); to prevent Cross-Site Scripting.


There was recently a thread on the php-dev mailing list about this. The reason you can't access 'hub.challenge' in the $_GET superglobal is due to register_globals. Basically PHP cleans up any argument names before creating the superglobals. Any dots will be converted to underscores. It's looking to be 'fixed' in PHP 6, but not before due to BC issues.

Here's the thread about it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号