I`m trying to find a way to use the retrieved values I receive from my SMS Messaging Provider, the values I receive is:
0|IN_PROGRESS|225161649
Where I need to store certain values in my database.
Here is a url to where I receive my values:
http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0?username=xxxx&password=xxxxx&message=Hi+Mom+%26+Dad&msisdn=44423456789
This will return values:
23|invalid credentials (username was: xxxx)|
Now I need to get the values and store in PHP variable to process to my database.
Here is my form that submits the data:
$mobile = $_POST['mobile'];
$text = $_POST['textcounter'];
$username = 'xxxx';
$password = 'xxxx';
// Set Timezone
date_default_timezone_set('Africa/Johannesburg');
$date = date("m/d/y G.i:s", time());
// Create Unique ID
$code = md5(time());
$newid = $code.$clientid;
$sql="INSERT INTO sms_sent (sent_id, sent_message, sent_date, sent_quantity, client_id, sent_mobile)VALUES('$newid', '$text', '$date', '1', '$clientid', '$mobile')";
$result=mysql_query($sql);
$url = "http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0"; // URL to calc.cgi
$fields = array(
'site'=>'',
'username'=>($username),
'password'=>($password),
'message'=>urlencode($text),
'msisdn'=>urlencode($mobile)
);
$fields_string="?";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
ob_start();
curl_exec($ch);
ob_end_clean();
echo '<div class="alert alert-block alert-success">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading">Success!</h4>
Your message has been Sent!
</div><br/><br/>Search Contact';
//close connection
curl_close($ch);
}
Any suggestions please.
You can use explode function
<?php
$responseParams=explode("|",response);
foreach($responseParams as $params)
{
echo $params;
}
?>
Further reference
http://php.net/manual/en/function.explode.php
try:
rtrim($fields_string,'&');
rtrim Returns String and does NOT modify arguments.
Related
I am trying to add leads from my contact form to salesforce. Currently I am using this solution that passes them through what I assume is the Web-to-Lead solution they have:
if (isset($_POST['submit'])) {
$ch_register_first_name = $_POST['ch_register_first_name'];
$ch_register_last_name = $_POST['ch_register_last_name'];
$ch_register_dob = $_POST['ch_register_dob'];
$ch_register_phone = $_POST['ch_register_phone'];
$ch_register_email = $_POST['ch_register_email'];
$ch_register_street = $_POST['ch_register_street'];
$ch_register_street2 = $_POST['ch_register_street2'];
$ch_register_city = $_POST['ch_register_city'];
$ch_register_state = $_POST['ch_register_state'];
$ch_register_zip = $_POST['ch_register_zip'];
//set POST variables
$url = 'https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$fields = array(
'last_name'=>urlencode($ch_register_first_name),
'first_name'=>urlencode($ch_register_last_name),
'street'=>urlencode($ch_register_street),
'city'=>urlencode($ch_register_city),
'state'=>urlencode($ch_register_state),
'zip'=>urlencode($ch_register_zip),
'company'=>urlencode($company),
'description'=>urlencode($ch_register_dob),
'email'=>urlencode($ch_register_phone),
'phone'=>urlencode($ch_register_email),
'mycustomefieldid' => urlencode($ch_register_dob), // custom field
'oid' => $ch_register_salesforce_id, // insert with your id
'retURL' => urlencode('http://thank-you/'), // sending this just in case
'debug' => '1',
'debugEmail' => urlencode("email#email.com"), // your debugging email
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
The issue by doing this (if I am correct that its using the Web-to-Lead solution) the max limit is 500 in 24hrs. Some events this form will be used at day of will have more than 500 for sure. How can I use just their API I have read about? Or should I save the locally to the database then run a batch using the Force api?
I have following code:
jQueryjQuery('#test').submit(function(e){
e.preventDefault();
var empno=jQuery('#empno').val();
var msg=jQuery('#msg').val();
var rem_url="url=http://10.32.2.251/Dept/esl/rem_sms.php&msg="+ msg +"&empno="+empno;
jQuery.post("curl_request.php", {"dest_url":rem_url }, function(data) {
alert (data);
});
});
Below is the curl_request.php page code.
<?php
//set POST variables
$url = $_POST['url'];
unset($_POST['url']);
$fields_string = "";
//url-ify the data for the POST
foreach($_POST as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
$fields_string = rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($_POST));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
if($result === FALSE) {
echo curl_error($ch);
}
//close connection
curl_close($ch);
?>
The other domain page rem_sms.php take two parameters,msg & empno; But I am getting error malformed. No more details . What is wrong with my code?
The problem is in your javascript code. You are posting 'dest_url' variable is in php script you are using 'url'. Change the following two lines in your curl_request.php.
$url = $_POST['dest_url'];
unset($_POST['dest_url']);
Instead of
$url = $_POST['url'];
unset($_POST['url']);
Also update
var rem_url="url=http://10.32.2.251/Dept/esl/rem_sms.php&msg="+ msg +"&empno="+empno; BY
var rem_url="http://10.32.2.251/Dept/esl/rem_sms.php&msg="+ msg +"&empno="+empno;
I've been trying to use the code below to send sms but it does not send when I loop. It only works if I just pick one number from database. I have over 5,000 numbers in the database and wish to send an sms to all of them at the same time, Please help.
mysql_select_db($database_xxx, $xxx);
$query_rs = "SELECT phone FROM `notify` order by id asc LIMIT $l1 , $l2";
$rs= mysql_query($query_rs, $xxx) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs= mysql_num_rows($rs);
$phone = $row_rs['phone'];
// Do while loop to send sms.
while($row=mysql_fetch_assoc($rs)){
// Let's do some formatting and keep smiling.
$giringirin = ereg_replace("[^0-9]", "", $phone );
if (strlen($giringirin) == 11) {
$phone1=substr($giringirin, 1);
$phone= "234$phone1";
} elseif (strlen($giringirin) == 13){
$phone = $giringirin;
}
extract($_POST);
//set POST variables
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";
$fields = array(
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
if ($result == '1801') { echo "SMS has also been sent to the Customer ($phone) \n";} else { echo "Oooops, No sms was sent";}
//close connection
curl_close($ch);
}
Your code is confusing...
curl_setopt($ch,CURLOPT_POST,count($fields));
CURLOPT_POST is a boolean flag. Either you're doing a post, or you're not. The number of fields you're posting is irrelevant.
You're building up a series of variables/values to be posted, but doing it via string operations. CURL is perfectly capable of taking an array and doing all that for you, reducing your entire foreach loop to just
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
You're using extract() on $_POST, which pollutes your script's variable namespace with any garbage a malicious user cares to send over - you're essentially replicating PHP's utterly moronically brain-dead register_globals all over again.
You're using ereg, which has been deprecated for approximiately 5 million internet years. You should be using the preg functions insteadl
What happens when you run this script in the browser? Blank page? Something? Error?
Start by changing
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";
to
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=".$username."&password=".$password."&message=".$smsmessage."&mobile=".$phone."&sender=".$sender."";
I`m trying to create a script sending information from 1 domain to another and saving the data to a database, however i retrieve data from domain 1, but cant save to the database.
Here is the script from domain 1:
// Get Domain Name:
$domain = $_SERVER['HTTP_HOST'];
// Get User IP Address:
$user = $_SERVER["REMOTE_ADDR"];
// Connect to Source:
$url = 'http://www.domain2.com/source.php';
$fields = array(
'id'=>'1',
'user'=>$user,
'domain'=>$domain,
);
//url-ify the data for the POST
$fields_string = '?';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
Here is the script to save the data to the database on domain 2:
// Get domain and user details:
$domain=$_GET['domain'];
$user=$_GET['user'];
// Connection to MySQL Database.
include ('_includes/_dbconnection.php');
include ('_includes/_dbopen.php');
// Insert Data to MySQL Database
$sql="INSERT INTO traffic (url, cip)VALUES('$_POST[domain]', '$_POST[user]')";
$result=mysql_query($sql);
if($result){
echo $domain;
echo $user;
}
else {
echo 'Not Input';
}
You are posting the form with curl and trying to get the values with $_GET
Try to use $_POST or $_REQUEST
$domain=$_POST['domain'];
$user=$_POST['user'];
// Connection to MySQL Database.
include ('_includes/_dbconnection.php');
include ('_includes/_dbopen.php');
// Insert Data to MySQL Database
$sql="INSERT INTO traffic (url, cip)VALUES('$domain', '$user')";
$result=mysql_query($sql);
if($result){
echo $domain;
echo $user;
}else {
echo 'Not Input';
}
I am trying to execute a url and getting its response. Following is the code that executes the curl. I want the curl execution to return me a string in $result.
<?php
$fields = array
(
'username'=>urlencode($username),
'pwrd'=>urlencode($pwrd),
'customer_num'=>urlencode($customer_num)
);
$url = 'http://localhost/test200.php';
//open connection
set_time_limit(20);
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result; //I want $result to be "Successful"
?>
This is my test200.php on localhost:
<?php
$usernam = $_POST['username'];
$pass = $_POST['pwrd'];
$customer_num = $_POST['customer_num'];
echo "Successful!";
?>
What changes do I make in test200.php? Please help.
You should use the httpcode returned by the curl execution and not rely on a string that is returned
$res = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Here - http://www.webmasterworld.com/forum88/12492.htm
Once the data is sent to test200.php do the appropriate manipulation like insert the posted values into a table and on success
echo "Successful!";
or print the same in your test200.php.. assuming you are doing an insert code in test200.php code would be like
<?php
$qry = "INSERT INTO `your_table` (`field_customer_name`, `field_username`, `field_password`) VALUES ($fields['customer_num'], $fields['username'], some_encrypt_fxn($fields['pwrd']))";
mysql_query($qry);
$err_flag = mysql_error($your_conn_link);
if($err_flag == '') {
echo "Successful!";
}
else {
echo "Failed, Error " . $err_flag;
}
?>
If the purpose of getting "Successful!" is to check if the cURL returns success then i suggest using Prateik's answer of using the returned status code
Somehow a simple print("Successful"); statement in test200.php worked well. The response i get now is as follows: HTTP Code: 0 Array ( [0] => [1] => Successful )