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';
}
Related
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.
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 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 )
I have a php curl script that my sms gateway provided to enable me send sms via xml.The original script is what i have below.
////////////////////////////// original php curl xml code from gate way
<?php
$user="smsgateway_user";
$pass="smsgateway_password";
$sender= "sendername";
$mobileno="2348034057037";
$message= "Your sms message goes here";
?>
<?php
$postUrl = "http://www.infobip.com/AddOn/SMSService/XML/XMLInput.aspx";
// XML-formatted data
$xmlString =
"<SMS>
<authentification>
<username>$user</username>
<password>$pass</password>
</authentification>
<message>
<sender>$sender</sender>
<text>$message</text>
</message>
<recipients>
<gsm>$mobileno</gsm>
</recipients>
</SMS>";
// previously formatted XML data becomes value of “XML” POST variable
$fields = "XML=" . urlencode($xmlString);
// in this example, POST request was made using PHP’s CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// response of the POST request
$response = curl_exec($ch);
// redirect the page upon successful sending
header("Location:customized/successfullysentbulksms.php");
curl_close($ch);
?>
/// code end
I how ever tried to tweak the codes in order to enable me send customized multiple sms by connecting to a mysql table with the following fields (id,name,mobileno) in such as way that i can select 10 recipients and send a customized message so that each recipient get the same message with his name showing in the message such as " Dear(.$name),thank you for visiting our store today"
From the little php that i know, i believe that i am suppose to connect to the database to select my recipient and then write a "do or while loop" that will enable the script to repeat or loop this function till it has successfully sent sms to all the recipients.
I'm presently stuck with embedding my loop function, please i will be glad if someone can take a look at what i've done so far and help me out.
My tweaked version of the code ///////////////////////////////////////////
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="password"; // Mysql password
$db_name="db"; // Database name
$tbl_name="mysqltb"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Start looping rows in mysql database.
$row=mysql_fetch_array($result);
?>
<?
mysql_close();
?>
<?php
$mobileno = $row['mobileno'];
$name = $_row['name'];
$user="smsgateway_user";
$pass="smsgateway_password";
$sender= "sendername";
?>
<?php
$message = "you have received a customized bulk sms that is suppose to display your name";
$message2= "Dear ".$name." ".$message ;
$postUrl = "http://www.infobip.com/AddOn/SMSService/XML/XMLInput.aspx";
// XML-formatted data
$xmlString =
"<SMS>
<authentification>
<username>$user</username>
<password>$pass</password>
</authentification>
<message>
<sender>$sender</sender>
<text>$message2</text>
</message>
<recipients>
<gsm>$no</gsm>
</recipients>
</SMS>";
// previously formatted XML data becomes value of “XML” POST variable
$fields = "XML=" . urlencode($xmlString);
// in this example, POST request was made using PHP’s CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// response of the POST request
$response = curl_exec($ch);
// redirect the page upon successful sending
header("Location:customized/successfullysentbulksms.php");
curl_close($ch);
?>
Well there are a few things that I saw as I was looking through your code that were incorrect. The main things were 1) one of the $row variables was named $_row; 2) when you are looping through a query's return, you should use the standard pattern while ($row = mysql_fetch_array($result)), then each row will be looped through, instead you only fetched the first row.
Here is an example of what you wanted to do
<?php
$host = "localhost"; // Host name
$username = "user"; // Mysql username
$password = "password"; // Mysql password
$db_name = "db"; // Database name
$tbl_name = "mysqltb"; // Table name
$user = "smsgateway_user"; //sms user
$pass = "smsgateway_password"; //sms password
$sender = "sendername"; //sms sender name
$postUrl = "http://www.infobip.com/AddOn/SMSService/XML/XMLInput.aspx"; //XML Post url
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Retrieve data from database
$sql = "SELECT * FROM $tbl_name WHERE `send_status`=0";
$result = mysql_query($sql);
// Start looping rows in mysql database.
$totalCount = mysql_num_rows($result);
$successCount = 0;
while ($row = mysql_fetch_array($result))
{
$mobileno = $row['mobileno'];
$name = $row['name'];
$message = "Dear $name "; //Start message
$message .= "you have received a customized bulk sms that is suppose to display your name"; //append to message
// XML-formatted data
$xmlString =
"<SMS>
<authentification>
<username>$user</username>
<password>$pass</password>
</authentification>
<message>
<sender>$sender</sender>
<text>$message</text>
</message>
<recipients>
<gsm>$no</gsm>
</recipients>
</SMS>";
// previously formatted XML data becomes value of “XML” POST variable
$fields = "XML=" . urlencode($xmlString);
// in this example, POST request was made using PHP’s CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// response of the POST request
$response = curl_exec($ch);
//Might want to check the response here, see if it gives a true, or a 1 to say the message was sent successfully
if ($response)
{
$sql = "UPDATE `$tbl_name` SET `send_status`=1 WHERE `mobileno`='$mobileno' LIMIT 1";
$result = mysql_query($sql);
if (mysql_affected_rows($result) == 1) //success updating database
{
$successCount++;
}
}
// redirect the page upon successful sending
curl_close($ch);
}
if ($successCount == $totalcount)
header("Location:customized/successfullysentbulksms.php");
else
echo "Error Sending. $successCount out of $totalcount were successfully sent";
?>
Note: because this uses your database and sms provider, I haven't been able to test this code.
If you have any questions on how it works, I would be happy to answer them.
EDIT:
I have updated the code to include a mysql update statement to set the column 'send_status' to true after the message has been sent. I have also modified the mysql select statement to only get mobile numbers from the database that haven't been sent to yet (send_status is false).
Hope that helps
I want to loginto a site using curl and then get resulting page. for example i want to run a script and see my yahoo mail page. i wrote something like this.
//set POST variables
$url = 'http://localhost/test/login';
$fields = array(
'username'=>'abc',
'password'=>'def'
);
$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_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result;
login.php
echo $_POST['username'];
echo $_POST['password'];
header('Location: http://www.xyz.com/');
script posts data to login.php but contents of xyz.com are not shown.
By logging into a Website you normaly generate a Session ID which is stored in a Session. By logging in with CURL you didn't save this cookie in your Client Browser, you maybe logged in with your server, but there is no way to be logged in with your client.
And of course change this line:
echo $_POST['username'];
echo $_POST['password'];
header('Location: http://www.xyz.com/');
to the following:
header('Location: http://www.xyz.com/');
echo $_POST['username'];
echo $_POST['password'];
or use ob_start(); on the beginning of your script.
...which doesn't make sence because you'll never see that content ;)
Your problem is the two echo calls before the call to header.
According to the documentation header must be called before any other output is sent.
http://php.net/manual/en/function.header.php