File Manager
Editing: save-subscription.php
<?php // Save subscription endpoint to the database require __DIR__ . '/google-api-php-client--PHP8.3/vendor/autoload.php'; // Ensure you have the web-push-php library installed $host = "127.0.0.1:3306"; $username = "u404542307_dacotywebsites"; $password = "daCotywebs1te5"; $database = "u404542307_eizon"; $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get subscription data from the request $input = json_decode(file_get_contents('php://input'), true); $endpoint = $input['endpoint']; $p256dh = $input['keys']['p256dh']; $auth = $input['keys']['auth']; // Save subscription to the database $stmt = $conn->prepare("INSERT INTO push_subscriptions (endpoint, p256dh, auth) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $endpoint, $p256dh, $auth); if ($stmt->execute()) { echo json_encode(['status' => 'success']); } else { echo json_encode(['status' => 'error', 'message' => $stmt->error]); } $stmt->close(); $conn->close(); ?>
💾 Save
⬅ Back