Introduction
file_get_contents() is deprecated in favor of using the CURL libraries. You will occasionally run accross old code that uses the file_get_contents() that you want to use on servers with the file_get_contents functionality disabled. This shows how to convert from that function to the curl functions.
[edit]
file_get_contents code
$data = file_get_contents($remoteurl);
[edit]
curl code
//Initialize the Curl session
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $URL);
//Execute the fetch
$data = curl_exec($ch);
//Close the connection
curl_close($ch);
//$data now contains the contents of $URL
As a seasoned expert in AI, Machine Learning, Generative AI, IoT and Robotics, I empower innovators and businesses to harness the potential of emerging technologies. With a passion for sharing knowledge, I curate insightful articles, tutorials and news on the latest advancements in AI, Robotics, Data Science, Cloud Computing and Open Source technologies. Hire Me Unlock cutting-edge solutions for your business. With expertise spanning AI, GenAI, IoT and Robotics, I deliver tailor services.
Subscribe to:
Post Comments (Atom)
-
The client want to have a shop where regular customers to be able to see products with their retail price, while Wholesale partners to see t...
-
URL based session management does not only have additional security risks compared to cookie based session management, but it can cause also...
-
Widgets and gadgets are small applications that run on your desktop or in your web browser which enable you to keep track of things like the...
No comments:
Post a Comment