Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e37b702a6f
Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (37 sloc) 1.608 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?php
    // Include the PHP TwilioRest library
    require "twilio.php";
    
    // Twilio REST API version
    $ApiVersion = "2010-04-01";
    
    // Set our AccountSid and AuthToken
    $AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";

    // Create a new TwilioUtils object
    $utils = new TwilioUtils($AccountSid, $AuthToken);
    
    // Note, that if your URL uses an implied "index" document
    // (index.php), then apache often adds a slash to the SCRIPT_URI
    // while Twilio's original request will not have a slash
    // Example: if Twilio requested http://mycompany.com/twilio
    // and that url is handled by an index.php script
    // Apache/PHP will report the URI as being:
    // http://mycompany.com/twilio/
    // But the hash should be calculated without the trailing slash
           
    // Also note, if you're using URL rewriting, then you should check
    // to see that PHP is reporting your SCRIPT_URI and
    // QUERY_STRING correctly.
    
    if($_SERVER['HTTPS'])
        $http = "https://";
    else
        $http = "http://";
    
    $url = $http.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    
    if(isset($_POST)) {
        // copy the post data
        $data = $_POST;
    }
    
    $expected_signature = $_SERVER["HTTP_X_TWILIO_SIGNATURE"];
        
    echo "The request from Twilio";
    if($utils->validateRequest($expected_signature, $url, $data))
        echo "was confirmed to have come from Twilio.";
    else
        echo "was NOT VALID. It might have been spoofed!";
?>
Something went wrong with that request. Please try again.