xtraorange
xtraorange

Reputation: 1456

How do I handle data being sent from a source that can only use basic GET/POST requests in CakePHP?

I'm wondering what the proper MVC mannor of handling the following senario is with CakePHP:

I have a data source which is sending information to my website in the form of simple GET/POST requests. To make the illustration simple, let's say it's data coming in about pizza deliveries.

A POST from the source might contain a key/value combo of the driver's ID, the pizza's ID, and the current location of the pizza. The website then needs to respond to this data with a simple status message - a good example would simply be received/continue.

Now, I want this data to require some sort of basic authentication... this can work in any mannor, as long as it verifies that the data is from a valid source. I was thinking of just including POST data adding a userid and a passcode.

How do I incorporate this within CakePHP, so that it doesn't conflict in any way with other operations on the website, and also isn't overly exposed to security risks (mind that I doubt this will ever be a big enough website that someone will comb through it looking for holes).

Thank you! James

Upvotes: 1

Views: 69

Answers (1)

dr Hannibal Lecter
dr Hannibal Lecter

Reputation: 6721

There are several ways to accomplish this, so here's one off the top of my head:

  • The request data ($_POST data) should be available either in $this->request->data in your controller, or in the $_POST itself (or perhaps both).

  • To authenticate, you can use the good old HTTP Auth. Perhaps not the brightest/safest solution, but probably good enough for your needs. Also, it is already available in cake.

  • You can respond to the post in several ways:

    • by disabling the response rendering and outputting response in the controller ($this->autoRender = false; echo 'carry on old chap';)
    • or (my preferred way) set the response layout to ajax and echo the output in your view.

Last but not least, there is no reason why any of this should affect the rest of your app, knock yourself out!

Upvotes: 1

Related Questions