Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php api

<?php
header('Access-Control-Allow-Origin: *');

header('Content-Type: application/json; charset=UTF-8');

header("Access-Control-Allow-Methods: GET");

header("Access-Control-Max-Age:3600");

header("Access-Control-Allow-Headers:*");
Comment

rest api php

<?php
$con = mysqli_connect("Localhost", "root", "", "rest_api");
if (mysqli_connect_errno())
{
    echo "Connection Fail" . mysqli_connect_error();
}
header('Content-Type:application/json');
if (isset($_GET['token']))
{
    $token = mysqli_real_escape_string($con, $_GET['token']);
    $checkTokenRes = mysqli_query($con, "select * from api_token where token='$token'");
    if (mysqli_num_rows($checkTokenRes) > 0)
    {
        $checkTokenRow = mysqli_fetch_assoc($checkTokenRes);
        if ($checkTokenRow['status'] == 1)
        {
            if ($checkTokenRow['hit_limit'] <= $checkTokenRow['hit_count'])
            {
                $status = 'true';
                $data = "Api hit limit exceed";
                $code = '6';
            }
            else
            {
                mysqli_query($con, "UPDATE `api_token` SET `hit_count`= hit_count+1 WHERE `token` = '$token'");
                $sql = "select * from collected_data ";
                if (isset($_GET['id']) && $_GET['id'] > 0)
                {
                    $id = mysqli_real_escape_string($con, $_GET['id']);
                    $sql .= " where id='$id'";
                }
                $sqlRes = mysqli_query($con, $sql);
                if (mysqli_num_rows($sqlRes) > 0)
                {
                    $data = [];
                    while ($row = mysqli_fetch_assoc($sqlRes))
                    {
                        $data[] = $row;
                    }
                    $status = 'true';
                    $code = '5';
                }
                else
                {
                    $status = 'true';
                    $data = "Data not found";
                    $code = '4';
                }

            }

        }
        else
        {
            $status = 'true';
            $data = "API token deactivated";
            $code = '3';
        }
    }
    else
    {
        $status = 'true';
        $data = "Please provide valid API token";
        $code = '2';
    }

}
else
{
    $status = 'true';
    $data = "Please provide API token";
    $code = '1';
}
echo json_encode(["status" => $status, "data" => $data, "code" => $code]);
?>
Comment

create simple REST API php

You should consider looking at 
https://developer.okta.com/blog/2019/03/08/simple-rest-api-php#create-the-php-project-skeleton-for-your-rest-api
Comment

PREVIOUS NEXT
Code Example
Php :: php create empty array with size 
Php :: php file iterator 
Php :: entrust laravel 
Php :: remove jquery wp 
Php :: turn off wordpress user list exposed 
Php :: wpmu create user 
Php :: switch case or case php 
Php :: activerecord yii2 select with limit(start,end) not working 
Php :: show sender name laravel 
Php :: static variable php 
Php :: composer require rtconner/laravel-tagging 
Php :: laravel combo unique validation 
Php :: laravel-check-if-related-model-exists 
Php :: + php quantifer 
Php :: get time ISO 8601 wordpress 
Php :: laravel make model controller and migration one time 
Php :: laravel roles and permissions 
Php :: Undefined property: stdClass::$ 
Php :: php preplace 
Php :: php get day of week number 
Php :: magento 2 add in static block 
Php :: php get the two number of time second 
Php :: connexion à la base de donnée microsoftsqlserver avec php 
Php :: php add number to the existing name 
Php :: delete laravel error log 
Php :: Update Data Multiple Columns MySql Database Table PHP Function 
Php :: how to check if page opened from mobile or desktop 
Php :: shortcode wordpress form 
Php :: php barcode generator 
Php :: laravel many to many relationship 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =