0

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.

1
  • curl example: stackoverflow.com/questions/2440252/… this is the quick way to handle this. Web services may be more appropriate if other developers at other companies need to use this Commented Feb 15, 2012 at 23:54

2 Answers 2

1

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:

<img src="http://yoursite.com/your_script.php" />

And your_script.php does 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!

Sign up to request clarification or add additional context in comments.

2 Comments

i think web service is the way to go. What do you mean by not letting them execute php code?
When you said, "the other pages could be developed by other people uploaded to the site," I got (perhaps mistakingly) the impression that you were going to allow untrusted users to upload their own PHP pages on your server, and that is a gigantic security vulnerability.
1

Why don't you just include the script and call a function in it?

UPDATE: based on your comments below, I'd recommend some sort of web service and then the "pages" that need access to the save can use cURL.

4 Comments

the other pages might be in different servers.. and the other pages could be developed by other people uploaded to the site, and we just want to provide access to the database through a link
You need to be clearer in your question then. You didn't mention any of this.
sorry about that.. by using webservice, does it mean I need to use SOAP?
That is entirely up to you. I'd recommend something RESTful, but that is just my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.