I want to execute few curl commands from my Drupal site using PHP.
Idea is to create a custom content type that accepts php code. I understood from the internet I have to create a file "node--page.tpl.php" and add the below code in this file.
- Will this actually work?
- If yes, at which path should I place node--page.tpl.php file?
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<Relavent Tags/>
<title>My Page</title>
</head>
<body>
<h3 style="text-align:center;">Heading</h3>
<?php
$url = "Service Endpoint";
// Initializing curl
$curl = curl_init();
// Sending GET request to reqres.in
// server to get JSON data
curl_setopt($curl, CURLOPT_URL, $url);
// Telling curl to store JSON
// data in a variable instead
// of dumping on screen
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
// Executing curl
$response = curl_exec($curl);
// Checking if any error occurs
// during request or not
if($e = curl_error($curl)) {
echo $e;
} else {
// Decoding JSON data
$decodedData = json_decode($response, true);
// Outputting JSON data in
// Decoded form
print_r($decodedData);
}
// Closing curl
curl_close($curl);
?>
</body>
</html>