I have a php script that I’m trying to pull some data from a database on one site and display it on another site. I need to reference some files, but using require filename.php throws errors due to my allow_url_fopen being set to off for security reasons. Is there an alternative way to “require” the file using cURL instead?
Example OLD:
<?php require ('http://site.com/filename.php'); ?>
I tried this, but it doesn’t work:
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://site.com/filename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
// display file
require $file_contents;
?>
Ms. Ramsey,
The most widely accepted solution for your problems in 2011 is to use what’s called a RESTful architecture, which was first widely championed by Yahoo a few years back. It’s REALLLLLLLY easy and not complicated at all as you will soon see.
First, on the “server” side (where you’re receiving the information) you create a simple RESTful server, the most simplistic one I can think of being (coding on the spot here):
Now, on your client side, all you have to do is this:
It actually works pretty nicely.
I hope you pick my answer!