- 8 Ocak 2011
- 103
- 47
Merhaba.
Bugün örnek bir web sitesi ile karşınızdayım.
Bu web sitesinde kripto paraların fiyatlarını ve çeşitli bazı verileri görüntüleyebiliyoruz.
Kendim kodladım...
Bir api servisi (coincap) kullanarak istenilen kripto parayla ilgili verileri apiden çekip yazdırıyoruz.
Görseller ;
Kodlar ;
index.php
Bugün örnek bir web sitesi ile karşınızdayım.
Bu web sitesinde kripto paraların fiyatlarını ve çeşitli bazı verileri görüntüleyebiliyoruz.
Kendim kodladım...
Bir api servisi (coincap) kullanarak istenilen kripto parayla ilgili verileri apiden çekip yazdırıyoruz.
Görseller ;
Kodlar ;
index.php
PHP:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Klamhat Crypto</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url('arkaplan.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.container {
max-width: 800px;
height: 700px;
margin: 50px auto;
background-color: rgba(255, 255, 255, 0.7);
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: rgba(255, 255, 255, 0.7);
overflow: hidden;
}
h1 {
text-align: center;
}
#search {
text-align: center;
margin-bottom: 20px;
}
#search input[type="text"] {
padding: 13px;
height: 12px;
border: 1px solid #ccc;
border-radius: 4px;
margin-right: 10px;
}
#search button {
padding: 10px 20px;
background-color: black;
color: #fff;
font-size: 14px;
border: none;
border-radius: 4px;
cursor: pointer;
}
#prices {
padding: 20px;
border-top: 1px solid #ccc;
}
#prices h2 {
margin-top: 0;
font-size: 24px;
color: green;
}
#prices p {
margin: 5px 0;
font-size: 18px;
}
#prices ul {
list-style-type: none;
padding: 0;
}
#prices li {
margin-bottom: 5px;
}
.disclaimer {
text-align: center;
margin-top: 20px;
font-size: 18px;
color: black;
}
</style>
<script>
window.onload = function() {
var coinName = document.querySelector('#prices h2').textContent;
document.title = "Klamhat Crypto | " + coinName;
}
</script>
</head>
<body>
<div class="container">
<h1>Klamhat Crypto Tracking</h1>
<div id="search">
<form method="post">
<input type="text" name="coin" placeholder="Write a cryptocurrency">
<button type="submit" name="submit">Search</button>
</form>
</div>
<div id="prices">
<?php include 'fetch_prices.php'; ?>
</div>
<p class="disclaimer">Data may lag, it is important to check different sources for correct analysis!</p>
</div>
</body>
</html>
fetch_prices.php
PHP:
<?php
error_reporting(E_ERROR | E_PARSE);
if(isset($_POST['submit'])) {
$coin = $_POST['coin'];
$url = "https://api.coincap.io/v2/assets/$coin";
$data = @json_decode(file_get_contents($url));
if ($data && isset($data->data) && $data->data) {
echo "<h2>{$data->data->name} ({$data->data->symbol})</h2>";
echo "<p>Price: $ <strong>" . number_format($data->data->priceUsd, 2, '.', ',') . "</strong></p>";
echo "<p>24 Hour Change: <strong>{$data->data->changePercent24Hr}%</strong></p>";
echo "<h3>Other Information:</h3>";
echo "<ul>";
foreach ($data->data as $key => $value) {
if (!is_object($value) && !is_array($value)) {
$formattedValue = is_numeric($value) ? number_format($value, 2, '.', ',') : $value;
if ($key == 'priceUsd') {
echo "<li><strong>Price:</strong> $formattedValue $</li>";
} elseif ($key == 'changePercent24Hr') {
echo "<li><strong>24 Hour Change:</strong> $formattedValue%</li>";
} elseif ($key == 'marketCapUsd') {
echo "<li><strong>Market Cap:</strong> $formattedValue $</li>";
} elseif ($key == 'volumeUsd24Hr') {
echo "<li><strong>24 Hour Volume:</strong> $formattedValue $</li>";
} elseif ($key == 'supply') {
echo "<li><strong>Supply:</strong> $formattedValue $</li>";
} elseif ($key == 'maxSupply') {
echo "<li><strong>Max Supply:</strong> $formattedValue $</li>";
} elseif ($key == 'rank') {
echo "<li><strong>Rank:</strong> $formattedValue</li>";
} elseif ($key == 'id') {
echo "<li><strong>ID:</strong> $formattedValue</li>";
} else {
echo "<li><strong>$key:</strong> $formattedValue</li>";
}
}
}
echo "</ul>";
} else {
echo "<p style='color: red;'>The cryptocurrency you entered could not be found. Please enter a valid cryptocurrency name.</p>";
}
}
?>