Example: fopen()
fopen is not allowed on this host.
fopen is not allowed on this host.
<?php
include('includes/header.php');
echo("<h2>Example: fopen() </h2>");
ini_set('display_errors', 1);
// Check if 'allow_url_fopen' is enabled before proceeding
if (ini_get('allow_url_fopen') == 1)
{
echo "fopen is allowed on this host.<br><br>";
// OpenWeather API
echo "OpenWeather" . " ";
echo('https://openweathermap.org/');
echo("<br>");
$api_url = "https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key";
$handle = fopen($api_url, "r");
if ($handle)
{
echo("<p>OpenWeather API Data:</p>");
while (($line = fgets($handle)) !== false)
{
echo strip_tags($line);
}
fclose($handle);
}
else
{
echo "Error opening OpenWeather API file.";
}
echo("<br><br>");
// JSONPlaceholder API
echo "JSONPlaceholder" . " ";
echo "https://jsonplaceholder.typicode.com/";
echo("<br>");
$json_url = "https://jsonplaceholder.typicode.com/posts/1";
$handle = fopen($json_url, "r");
if ($handle)
{
echo("<p>JSONPlaceholder API Data:</p>");
while (($line = fgets($handle)) !== false)
{
echo strip_tags($line);
}
fclose($handle);
}
else
{
echo "Error opening JSONPlaceholder API file.";
}
echo("<br><br>");
// OpenStreetMap API
echo "OpenStreetMap API" . " ";
echo "https://nominatim.openstreetmap.org/";
echo("<br>");
$map_url = "https://nominatim.openstreetmap.org/search?q=London&format=json";
$handle = fopen($map_url, "r");
if ($handle)
{
echo("<p>OpenStreetMap API Data:</p>");
while (($line = fgets($handle)) !== false)
{
echo strip_tags($line);
}
fclose($handle);
}
else
{
echo "Error opening OpenStreetMap API file.";
}
echo("<br><br>");
// Data.gov
echo "Data.gov" . " ";
echo "https://data.gov/";
echo("<br>");
$csv_url = "https://example.com/dataset.csv";
$handle = fopen($csv_url, "r");
if ($handle)
{
echo("<p>Data.gov API Data:</p>");
while (($line = fgets($handle)) !== false)
{
echo strip_tags($line);
}
fclose($handle);
}
else
{
echo "Error opening Data.gov file.";
}
echo("<br><br>");
// GitHub raw file
echo "GitHub" . " ";
echo "https://github.com/";
echo("<br>");
$raw_url = "https://raw.githubusercontent.com/user/repo/main/data.txt";
$handle = fopen($raw_url, "r");
if ($handle)
{
echo("<p>GitHub Raw Data:</p>");
while (($line = fgets($handle)) !== false)
{
echo strip_tags($line);
}
fclose($handle);
}
else
{
echo "Error opening GitHub raw file.";
}
}
else
{
echo '<p style="color: #A00;">fopen is not allowed on this host.</p>';
}
include('includes/footer.php');
?>