Team 4’s Infrared IoT Door Security Code

<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;

// Check if phone number send in request
if(isset($_GET['n'])) {
    
    // New Twilio client, credentials saved in environment
    $client = new Client($_ENV["TWILIO_SID"], $_ENV["TWILIO_AUTH_TOKEN"]);
    $client->messages->create(
        '+'.$_GET['n'],
        array(
            'from' => "+1xxxxxxxxxx",    //xxx.. = phone number including area code
            'body' => '-------------------- Alert, Door Open --------------------'
        )
    );
    echo "200 OK";
    http_response_code(200);
    
} else {
    
    // Error
    echo "400 Bad Request\nMissing phone number";
    http_response_code(400);
    
}

The above code was the file that we used for the endpoint server that actually received the inputs from the Wi-Fi board, and then is used to check if there is a valid phone number to message. If the phone number is missing or invalid, then it returns an error code of 400. However, if it has a valid number but has not received an input from the circuit then it continues to respond with an “ok” status code only to the http server. Then, when both a valid number is stored and the file receives the input it creates a new message and sends it to say that the door has been opened, and sends it using the ‘from’ listed number.