0

send sms and store value in database using webapi

i want to save some response to the database of my website

so i have to work with two files as i read a blog post and the files content is

and i added link of my first file to tropo app

first:

<?php
// The URL where the test-auth.php script resides.
require 'tropo.class.php';

define("POST_DATA_TO_URL", "http://xyz.org/wp-content/themes/lc-blank/testit.php");
//define("shortcode", "+144140");

// Function to send value to my-script.php script via cURL with digest authentication.
function submitValue($myValue) {
$ch = curl_init(POST_DATA_TO_URL);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, "admin:mypass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "myValue=$myValue");

$output = curl_exec($ch);

if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != '200') {
return null;
}
return $output;
}


$suc="success";
$tropo = new Tropo();
$params = array(
'to' => '+16665554444',
'name' => 'MyName'
);
$tropo->message("this is simple test sms.", $params);

submitValue($suc);
?>

 

second is :

 

<?php
/*
* Simple Digest Authentication script for accepting HTTP POSTs from Tropo.
* Modified from example in PHP Manual - http://php.net/manual/en/features.http-auth.php
*/

// Function to parse the http auth header.
function http_digest_parse($txt) {
// protect against missing data
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
$data = array();
$keys = implode('|', array_keys($needed_parts));

preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);

foreach ($matches as $m) {
$data[$m[1]] = $m[3] ? $m[3] : $m[4];
unset($needed_parts[$m[1]]);
}

return $needed_parts ? false : $data;
}

define("REALM", "My Restricted area");

// A simple aray to hold usernames and passwords.
$users = array('admin' => 'mypass', 'guest' => 'guest');

if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="'.REALM.'",qop="auth",nonce="'.uniqid().'",opaque="'.md5(REALM).'"');
die('Not authorized!');
}

// Analyze the PHP_AUTH_DIGEST variable.
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($users[$data['username']]))
die('Wrong Credentials!');

// generate the valid response
$A1 = md5($data['username'] . ':'.REALM.':' . $users[$data['username']]);
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);

// If the wrong credentials are given, respond with a 403.
if ($data['response'] != $valid_response) {
header('HTTP/1.1 403 Forbidden');
die('Wrong Credentials!');
}

// Otherwise, sanitize the submitted value and insert into a MySQL database.
else {

try {

$conn = mysqli_connect('host', 'username', 'password');
$myValue = mysqli_real_escape_string($_POST['myValue'], $conn);
mysqli_select_db('my-database', $conn);

if(mysqli_query("INSERT INTO my-table values ($myValue)", $conn)) {
header('HTTP/1.1 200 OK');
echo "SUCCESS";
}
else {
throw new Exception(mysql_error());
}


}
catch (Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
echo "FAILURE: ".$ex->getMessage();
}
}


?>

 

but i am not getting any sms and not any update in my datagase

 

2 comments

Please sign in to leave a comment.