Passing json file via cUrl in php
We will implement passing json file via cUrl and submit to next server. cUrl is all about special communication between two or more server. Such as server1.com sending data to server2.com. A lot of beginner had always ask endless question about what is cUrl and what cUrl actually does. A simple answer there is: cUrl is a special communication between two or more server. Now, if you look at json code below, it has been neatly written and indented and ready for testing. Launch your notepad copy the json data below and save it as data.json place it in a folder where you saved other php file.
Php passing data from server.com to server.com using cUrl
In the php code below, it will send data from server1.com to server2.com. First, it connect server2.com, get json file, decode it, store it in php array and send it to server2.com, server2.com will process the data and print it out. Now, copy the below code and save it as index.php in the same folder where you saved the data.json file
Php script to receive a request coming server1.com using cUrl
In below php code, this code should be placed in server2.com. When a request is coming from server1.com this php script will receive the request and process the data and print it to the stream. Now, copy the php code below and place it in server2.com for testing. Then type the url from server1.com which will trigger and process the php script and return the output.
".$image."
"; echo "".$fullname."
"; echo "".$fulladdress."
"; echo "".$emailaddress."
"; echo "".$phonenumber."
"; echo "".$username."
"; echo "".$password."
"; echo "".$project."
"; echo "".$subscription."
"; echo "".$gender."
"; echo "".$reg_date."
"; ?>Summary
While testing the above script, if you have no access to two server you can test it in same server. You can place the second php code in deferent folder. If everything goes well it will run and return the output. If you encounter error messages from php, don't hesitate to get in touch, we are open to respond to your question.
Comments