I have a few php pages that might want to access the database and insert data into it. Now, I have a PHP script (save_data.php) that does the insert. It gets the input via POST then insert the data into database.
I want the other pages to be able to call/hit the save_data.php and send parameters via POST so that those pages dont have to directly access the database. After hitting the save_data.php, the other pages, must resume loading their own HTML codes.
I’ve read about cURL in PHP and using WebServices but Im not sure which one is appropriate or is there any other way? Thanks.
Based on your comments on other answers, it sounds like you want to provide access to the your save scripts to other servers and developers. The standard best practice way to do this is to offer a Web Service. Either an API that can be accessed via cURL, REST, or maybe even expose a SOAP server.
There’s an old school trick to do some of these things, though, if you’re looking for a quick and easy way to expose this script. You can use image embedding in HTML, kind of like how old school site counters work.
The page includes an image:
And
your_script.phpdoes your database write logic, and responds with the appropriate MIME type, plus the data of a blank GIF.This is used more often to share cookies across multiple domains and services using multiple types of technologies, but could work in your case.
I’m not advising its the BEST way to go. But it could work for you.
Edit
Another reason I outlined this solution is because it does not require PHP on the initial page. When your question stated that the pages may be uploaded by users, I got heart palpitations thinking about user uploaded PHP including your PHP. Please don’t let users upload and execute PHP code. Please oh please!