I am using the service from bitping.net which uses a HTTP POST to send event data to my php script on my site.
When an event is posted the data is inserted into a database and then triggers a SMS via the twilio script. For some reason my test event would run the script fine; insert the data and return info via SMS.
but the actual event, a bitcoin transfer does not trigger the SMS! BUT it does store all the vaules! hash/amount block ext!...
After a ton of debugging I tracked down the point where it stops working
I have it broken into 3 parts.
Data.php the main file
Addresscheck.php
RequireDebug.php
I can only run two of these at a time. Data.php and require ("addresscheck.php"); or data.php and require ("requireDebug.php");
Both do work independently if I comment out the other include.
I tried having one database, tried breaking it into two. (The way it is now)
I keep thinking it must be a problem with the site bitping.net
But every time data is passed into the database. Test/or real event. It is the twillio that is failing to trigger.
It seems insane to me the Test event HTTP POST would be any different from the real event.
I’ve been pounding my head with this craziness; any pointers?
//Call the 2 databases
$conn = new mysqli('localhost', 'Admin', 'XXXXXXXX','MDHoldings');
//debug PASS
//bitping HTTP post, but should work for Pubnub
$to_address = $_POST["to_address"];
$amount = $_POST["amount"];
$btc = $_POST["btc_amount"];
$confirmations = $_POST["confirmations"];
$txhash = $_POST["txhash"];
$block = $_POST["block"];
$sig = $_POST["signature"];
$mysig = sha1(
$address .
$amount .
$confirmations .
$txhash .
$block .
"f632c83ad0f5a44d9a169902ff18b3ed"
);
if ($mysig === $sig)
{
//check if number of confirmations is ok
//update order/send user notification
} else {
//log all post data, send warning email to administrator
}
//get data
//require ("requireDebug.php");
//store DATA
$sql = "INSERT INTO `transactions` (`to_address`, `txhash`, `USD`, `amount`, `block`)
VALUES ('$to_address', '$txhash', '$USD','$amount','$block')";
//KEEP TRACK OF IF's
if ($conn->query($sql) === TRUE) {
echo 'users entry saved successfully';
}
else {
echo 'Error: '. $conn->error;
}
//Debug PASS
require ("addresscheck.php");
//debug 2
//require ("requireDebug.php");
//********** WHY CAN I ONLY Use 1?! If I only select one at a time, not both!?
$cell = XXXXXXXXXX;
//$Data = test;
/* Send an SMS using Twilio. You can run this file 3 different ways:
*
* - Save it as sendnotifications.php and at the command line, run
* php sendnotifications.php
*
* - Upload it to a web host and load mywebhost.com/sendnotifications.php
* in a web browser.
* - Download a local server like WAMP, MAMP or XAMPP. Point the web root
* directory to the folder containing this file, and load
* localhost:8888/sendnotifications.php in a web browser.
*/
// Step 1: Download the Twilio-PHP library from twilio.com/docs/libraries,
// and move it into the folder containing this file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "XXXXXXXXXXXXXXXXXXXXXXXXX";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"$cell" => "$user",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->sms_messages->create(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"XXXXXXXXXXXXX",
// the number we are sending to - Any phone number
$number,
// the sms body
" $test $name, There has been a deposit to $Account : $baddress you have $USD$ of new funds in your account. Recipt $txhash "
);
// Display a confirmation message on the screen
echo "Sent message to $name $amount";
}
$conn->close();
?>
requireDebug.php
$conn = new mysqli('localhost', 'worker', 'XXXXXXX','test');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// sql query for INSERT INTO users (two rows)
// SELECT sql query
$sql = "SELECT `id`, Price FROM `Intake` ORDER BY id DESC LIMIT 1";
// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
// output data of each row from $result
while($row = $result->fetch_assoc()) {
$rate = $row['Price'];
}
}
else {
echo '0 results';
}
//$Data = $row['Price'];
echo ($rate);
$conn->close();
$USD = ($amount * $rate)/100000000;
?>
addresscheck.php
// CONNECT TO THE DATABASE
$conn = new mysqli('localhost', 'Admin', 'XXXXXXX','MDHoldings');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// sql query for INSERT INTO users (two rows)
// SELECT sql query
$sql2 = "SELECT * FROM Accounts WHERE Address = '$to_address'";
// perform the query and store the result
$result2 = $conn->query($sql2);
// if the $result contains at least one row
if ($result2->num_rows > 0) {
// output data of each row from $result
while($row2 = $result2->fetch_assoc()) {
$Account = $row2['Account'];
}
}
else {
echo '0 results';
}
//echo ($test);
//echo ($Account);
//echo ($user_email);
//echo ($Balance);
$conn->close();
?>