Пользователь
- Сообщения
- 5
- Реакции
- 1
How to get json data from Counter-Strike files to the online website? + I need some examples please.
Counter-Strike 1.6Supremache, 1.6 or GO
<?php
// JSON verilerini oluşturma
$data = array(
"player_name" => "Player1",
"score" => 1500,
"kills" => 10,
"deaths" => 5
);
// JSON formatına dönüştürme
$json_data = json_encode($data);
// API URL'si
$url = 'https://yourwebsite.com/api/receive_data.php';
// cURL ile verileri gönderme
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
// Yanıtı kontrol etme
echo $response;
?>
<?php
// JSON verilerini alma
$data = json_decode(file_get_contents('php://input'), true);
// Verileri işleme (örneğin, veritabanına kaydetme)
if ($data) {
$player_name = $data['player_name'];
$score = $data['score'];
$kills = $data['kills'];
$deaths = $data['deaths'];
// Veritabanına kaydetme işlemleri burada yapılabilir
// Başarılı yanıt
echo json_encode(array("status" => "success", "message" => "Data received."));
} else {
// Hata durumu
echo json_encode(array("status" => "error", "message" => "No data received."));
}
?>
Thanks for helpHere's a simple example sending JSON data to a web service using PHP:
PHP:<?php // JSON verilerini oluşturma $data = array( "player_name" => "Player1", "score" => 1500, "kills" => 10, "deaths" => 5 ); // JSON formatına dönüştürme $json_data = json_encode($data); // API URL'si $url = 'https://yourwebsite.com/api/receive_data.php'; // cURL ile verileri gönderme $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $response = curl_exec($ch); curl_close($ch); // Yanıtı kontrol etme echo $response; ?>
If your website doesn't have an API to receive incoming JSON data, you should create one, here's a simple example:
When a certain event occurs on your Counter-Strike server (for example, a player joins the game or game over, kill, score status, etc.) you can run the PHP script above. This way you can send JSON data to your online website.PHP:<?php // JSON verilerini alma $data = json_decode(file_get_contents('php://input'), true); // Verileri işleme (örneğin, veritabanına kaydetme) if ($data) { $player_name = $data['player_name']; $score = $data['score']; $kills = $data['kills']; $deaths = $data['deaths']; // Veritabanına kaydetme işlemleri burada yapılabilir // Başarılı yanıt echo json_encode(array("status" => "success", "message" => "Data received.")); } else { // Hata durumu echo json_encode(array("status" => "error", "message" => "No data received.")); } ?>