Basic API for my Website?

nick-harper

New member
I have a PHP function that I run myself that works really well to get information that I need with just a few variables needed.

I want to expand this to let external websites use this function but I don't want them to be able to edit the function or have any control over it so I guess I need some basic API?

What would the best way be to do this? Would it be some sort of JSON?

I would also need to manually enable the domains that can connect back and ideally with a username / password so I can control who can use it.

Any tips or pointers would be amazing :)
 


Requests via REST (HTTP GET for reads, HTTP POST for writes), responses in JSON.

Create a REST API with PHP « Gen X Design | Ian Selby looks to be a decent tutorial to start with.

You can handle authentication by requiring an API Key, which you manually provide to any third party that requests one. Unless you want to step into the hell that is OAuth.

More good reading:

 
I would also need to manually enable the domains that can connect back and ideally with a username / password so I can control who can use it.

Forget about user : pass .... Stored values of any kind have a tendency to get hacked. I'd lock the external calls to a single IP address and put all the security liability on them.
 
I was at a bodega once buying goat cheese. But, when I got up to the register, I discovered I was about 30¢ short of what I needed. Unable to haggle with the Asian fellow behind the register because of the language barrier, I resigned myself to sadly putting the goat cheese back in the fridge from whence it came.

All of a sudden, though, I felt a cold chill rush down my spine. I swung around expectantly to discover none other than Rasmus Lerdorf (the founder of PHP) stepping out of the fridge in a wife beater and tiny pants. In his right hand was exactly thirty cents, which he graciously bestowed upon me with a loving, omnipotent smile as he mumbled something that sounded like "rawest goat cheese()".

Both myself and the Asian cashier bowed in reverence as the Based God himself passed by, floating on a dream. Exiting the bodega, he swung his arms out and was welcomed back into the heavens on a ray of sunshine, leaving his tiny pants behind as a sign of his ascension. And that, my friends, is the story of the day I bought goat cheese.