This is my code and I am using as external file include in my code as external file. When new user post this code is run but not sent message on all numbers that stored in database:
Error is:
Warning: fsockopen() [function.fsockopen]: unable to connect to :0
(Failed to parse address "") in C:\xampp\htdocs\funsmss\location\sendsms.php
Failed to parse address "" (0)
Here's the code:
<?php
$sql = "select * from subscribe where type ='$cat' and city ='$city'";
$query = mysql_query($sql);
if ($query != null) {
while ($row = mysql_fetch_array($query)) {
$name = $row['name'];
$phoneNum = $row['fone'];
$message = "Hi ".$name.", now you can buy your product.";
ozekiSend($phoneNum, $message);
// for debugging, try the following line
//echo ozekiSend($phoneNum, $message, true);
}
}
########################################################
# Login information for the SMS Gateway
########################################################
$ozeki_user = "admin";
$ozeki_password = "abc123";
$ozeki_url = "http://127.0.0.1:9501/api?";
########################################################
# Functions used to send the SMS message
########################################################
function httpRequest($url)
{
$pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern, $url, $args);
$in = "";
$fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
return("$errstr ($errno)");
} else {
$out = "GET /$args[3] HTTP/1.1\r\n";
$out .= "Host: $args[1]:$args[2]\r\n";
$out .= "User-agent: Ozeki PHP client\r\n";
$out .= "Accept: */*\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$in.=fgets($fp, 128);
}
}
fclose($fp);
return($in);
}
function ozekiSend($phone, $msg, $debug = false)
{
global $ozeki_user, $ozeki_password, $ozeki_url;
$url = 'username=' . $ozeki_user;
$url.= '&password=' . $ozeki_password;
$url.= '&action=sendmessage';
$url.= '&messagetype=SMS:TEXT';
$url.= '&recipient=' . urlencode($phone);
$url.= '&messagedata=' . urlencode($msg);
$urltouse = $ozeki_url . $url;
if ($debug === true) {
echo "Request: <br>$urltouse<br><br>";
}
//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug === true) {
echo "Response: <br><pre>" .
str_replace(array("<", ">"), array("<", ">"), $response) .
"</pre><br>";
}
return($response);
}
?>
Related
In the last month my patpal integration return error, i think that something change in the policy of paypal. this is the error:
[08/12/2021 11:59 AM] - FAIL: IPN Validation Failed.
IPN Response from Paypal Server:
HTTP/1.1 403 Forbidden
Content-Type: text/html
Content-Length: 38
Connection: close
DC: phx-origin-www-1.paypal.com
Strict-Transport-Security: max-age=31536000; includeSubDomains
<html><body>403 Forbidde</body></html>
its started in the last month.
this is the api url that i using:
https://api-3t.paypal.com/nvp
and this is the paypal class
<?php
class paypal_class {
var $last_error; // holds the last error encountered
var $ipn_log; // bool: log IPN results to text file?
var $ipn_log_file; // filename of the IPN log
var $ipn_response; // holds the IPN response from paypal
var $ipn_data = array(); // array contains the POST values for IPN
var $fields = array(); // array holds the fields to submit to paypal
function __construct() {
// initialization constructor. Called when class is created.
$this->paypal_url = 'https://ipnpb.paypal.com/cgi-bin/webscr';
$this->api_url = 'https://api-3t.paypal.com/nvp';
$this->last_error = '';
$this->ipn_log_file = 'ipn_log.txt';
$this->ipn_log = true;
$this->ipn_response = '';
// populate $fields array with a few default values. See the paypal
// documentation for a list of fields and their data types. These defaul
// values can be overwritten by the calling script.
// Return method = POST
$this->add_field('cmd', '_cart');
}
function add_field($field, $value) {
// adds a key=>value pair to the fields array, which is what will be
// sent to paypal as POST variables. If the value is already in the
// array, it will be overwritten.
$this->fields["$field"] = $value;
}
function submit_paypal_post($type = false) {
// this function actually generates an entire HTML page consisting of
// a form with hidden elements which is submitted to paypal via the
// BODY element's onLoad attribute. We do this so that you can validate
// any POST vars from you custom form before submitting to paypal. So
// basically, you'll have your own form which is submitted to your script
// to validate the data, which in turn calls this function to create
// another hidden form and submit to paypal.
// The user will briefly see a message on the screen that reads:
// "Please wait, your order is being processed..." and then immediately
// is redirected to paypal.
$form = array();
$output = "<html>\n";
$output .= "<head><title>טוען תשלום...</title></head>\n";
$output .= "<body onLoad=\"document.form.submit();\">\n";
$output .= "<form method=\"post\" name=\"form\" action=\"" . $this->paypal_url . "\">\n";
foreach ($this->fields as $name => $value) {
$output .= "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
$form[] = array(
"name" => $name,
"value" => $value,
"type" => "hidden"
);
}
$output .= "</form>\n";
$output .= "</body></html>\n";
if ($type)
return array("form" => $form, "action" => $this->paypal_url);
return $output;
}
function validate_ipn() {
// parse the paypal URL
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
foreach ($_POST as $field => $value) {
$this->ipn_data[$field] = $value;
$post_string .= $field . '=' . urlencode($value) . '&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
// open the connection to paypal
$fp = fsockopen("ssl://" . $url_parsed["host"], 443, $err_num, $err_str, 30);
if (!$fp) {
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results(false);
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST {$url_parsed["path"]} HTTP/1.1\r\n");
fputs($fp, "Host: {$url_parsed["host"]}\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($post_string) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while (!feof($fp)) {
$this->ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
}
if (preg_match("/VERIFIED/i", $this->ipn_response)) {
// Valid IPN transaction.
$this->log_ipn_results(true);
return true;
} else {
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
}
function log_ipn_results($success) {
if (!$this->ipn_log)
return; // is logging turned off?
// Timestamp
$text = '[' . date('m/d/Y g:i A') . '] - ';
// Success or failure being logged?
if ($success)
$text .= "SUCCESS!\n";
else
$text .= 'FAIL: ' . $this->last_error . "\n";
// Log the POST variables
$text .= "IPN POST Vars from Paypal:\n";
foreach ($this->ipn_data as $key => $value) {
$text .= "$key=$value, ";
}
// Log the response from the paypal server
$text .= "\nIPN Response from Paypal Server:\n " . $this->ipn_response;
// Write to log
$fp = fopen($this->ipn_log_file, 'a');
fwrite($fp, $text . "\n\n");
fclose($fp); // close file
}
function dump_fields() {
// Used for debugging, this function will output all the field/value pairs
// that are currently defined in the instance of the class using the
// add_field() function.
echo "<h3>paypal_class->dump_fields() Output:</h3>";
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
<tr>
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
</tr>";
ksort($this->fields);
foreach ($this->fields as $key => $value) {
echo "<tr><td>$key</td><td>" . urldecode($value) . " </td></tr>";
}
echo "</table><br>";
}
public function pay($username, $password, $signature, $email, $amount, $note = "Instant Payment") {
$version = urlencode("51.0");
$api = $this->api_url;
$type = urlencode("EmailAddress");
$currency = urlencode("USD");
$subject = urlencode("Instant Paypal Payment");
$string = "&EMAILSUBJECT=" . $subject . "&RECEIVERTYPE=" . $type . "&CURRENCYCODE=" . $currency;
$string .= "&L_EMAIL0=" . urlencode($email) . "&L_Amt0=" . urlencode($amount) . "&L_NOTE0=" . urlencode($note);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$request = "METHOD=MassPay&VERSION=" . $version . "&PWD=" . $password . "&USER=" . $username . "&SIGNATURE=" . $signature . "$string";
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$httpResponse = curl_exec($ch);
if (!$httpResponse) {
exit("MassPay failed: " . curl_error($ch) . '(' . curl_errno($ch) . ')');
}
$httpResponseArray = explode("&", $httpResponse);
$httpParsedResponse = array();
foreach ($httpResponseArray as $i => $value) {
$tempArray = explode("=", $value);
if (sizeof($tempArray) > 1) {
$httpParsedResponse[$tempArray[0]] = $tempArray[1];
}
}
if ((0 == sizeof($httpParsedResponse)) || !array_key_exists('ACK', $httpParsedResponse)) {
exit("Invalid HTTP Response for POST request($request) to " . $api);
}
return $httpParsedResponse;
}
}
what can i do?
i tried to search in google any policy update but no luck.
tnx
As mentioned in the IPN Integration Guide, ensure you include a User-Agent: field in your request headers, with a value that's any string > 7 characters or so
For live IPN verification, you should also use the domain ipnpb.paypal.com rather than www.paypal.com
i am working to send sms with ozeki NG and PHP, and i can send SMS from localhost but when i upload it on cpanel it says "fsockopen(): unable to connect to 197.XXX.XXX.XX:9501 (Connection timed out)"
IS THEIR ANY ONE WHO COULD HELP ME...thanks in advance...
$ozeki_user = "xxxx";
$ozeki_password = "xxxx";
$ozeki_url = "http://197.xxx.xxx.xxx:9501/api?";
function httpRequest($url){
$pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern,$url,$args);
$in = "";
$fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
return("$errstr ($errno)");
} else {
$out = "GET /$args[3] HTTP/1.1\r\n";
$out .= "Host: $args[1]:$args[2]\r\n";
$out .= "User-agent: Ozeki PHP client\r\n";
$out .= "Accept: */*\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$in.=fgets($fp, 128);
}
}
fclose($fp);
return($in);
}
function ozekiSend($phone, $msg, $debug=true){
global $ozeki_user,$ozeki_password,$ozeki_url;
$url = 'username='.$ozeki_user;
$url.= '&password='.$ozeki_password;
$url.= '&action=sendmessage';
$url.= '&messagetype=SMS:TEXT:UCS2';
$url.= '&recipient='.urlencode($phone);
$url.= '&messagedata='.urlencode($msg);
//$url.= '&messagedata='.urlencode($msg);
$urltouse = $ozeki_url.$url;
if ($debug) { echo "Request: <br>$urltouse<br><br>"; }
//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug) {
echo "Response: <br><pre>".
str_replace(array("<",">"),array("<",">"),$response).
"</pre><br>"; }
return($response);
}
$phonenum = $_POST['recipient'];
$message = $_POST['message'];
$debug = true;
ozekiSend($phonenum,$message,$debug);
?>
I am using Mailchimp api 1.3 php wrapper. The problem is that a server where my customer hosts a site will cache response, it won't even make api call. The exact the same code works with me and other customers:
$api = new MCAPI($apiKey);
$doubleOptin = false;
$mergeVar = array(
'FNAME' => '',
'LNAME' => ''
);
$api->listSubscribe($listId, $email, $mergeVar, 'html', $doubleOptin);
print_r($api);
method listSubscribe() calls method callServer where I guess is the problem:
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
$payload .= "Host: " . $host . "\r\n";
$payload .= "User-Agent: MCAPI/" . $this->version ."\r\n";
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
$payload .= "Connection: close \r\n\r\n";
$payload .= $post_vars;
ob_start();
if ($this->secure){
$sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
} else {
$sock = fsockopen($host, 80, $errno, $errstr, 30);
}
if(!$sock) {
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
$this->errorCode = "-99";
ob_end_clean();
return false;
}
$response = "";
fwrite($sock, $payload);
stream_set_timeout($sock, $this->timeout);
$info = stream_get_meta_data($sock);
while ((!feof($sock)) && (!$info["timed_out"])) {
$response .= fread($sock, $this->chunkSize);
$info = stream_get_meta_data($sock);
}
var_dump($response); exit;
Does anybody have any idea why fsockopen and fwrite never sends call to Mailchimp? Weird thing is that I can actually read $response, but it is always the same from cache.
If the code works for you and there is some query caching then you could try to add a timestamp to the request.
"&time=".time()
This way you always have a "fresh" request.
I am developing my first application in PHP using Curl. The purpose of this application is to develop an HTTP client which sends data to the server.
The server listens to port 10000 on # 192.168.1.110.
This is the server code:
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$address = '192.168.1.110';
$port = 10000;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() falló: razón: " . socket_strerror(socket_last_error()) . "\n";
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() falló: razón: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if (socket_listen($sock, 5) === false) {
echo "socket_listen() falló: razón: " . socket_strerror(socket_last_error($sock)) . "\n";
}
//clients array
$clients = array();
do {
$read = array();
$read[] = $sock;
$write = NULL;
$except = NULL;
$read = array_merge($read,$clients);
// Set up a blocking call to socket_select
if(socket_select($read,$write, $except, $tv_sec = 5) < 1)
{
continue;
}
// Handle new Connections
if (in_array($sock, $read)) {
if (($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() fail: " . socket_strerror(socket_last_error($sock)) . "\n";
break;
}
$clients[] = $msgsock;
$key = array_keys($clients, $msgsock);
/* Enviar instrucciones. */
$msg = "HTTP/1.1 100 Continue \n";
socket_write($msgsock, $msg, strlen($msg));
}
// Handle Input
foreach ($clients as $key => $client) { // for each client
if (in_array($client, $read)) {
if (false === ($buf = socket_read($client, 4096))) {
echo "socket_read() falló: razón: " . socket_strerror(socket_last_error($client)) . "\n";
break 2;
}
if (!$buf = trim($buf)) {
continue;
}
echo "$buf\n";
$talkback = "Client {$key}: msg '$buf'.\n";
socket_write($client, $talkback, strlen($talkback));
//echo "$buf\n";
}
}
} while (true);
socket_close($sock);
And this is the HTTP client's source code:
<?php
$url = 'http://192.168.1.110:10000';
$fields_string = "A";
$fields = array(
'SERIAL_NUMBER ' => urlencode('123456'),
'HARDWARE_ID ' => urlencode('455FFG'),
'CODE ' => urlencode('99'),
//field goes here
);
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
$ch = curl_init("http://192.168.1.110:10000");
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
crl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec($ch);
echo $output;
curl_setopt($ch,CURLOPT_POSTFIELDS,'test second session !!!!!');
$output = curl_exec($ch);
echo $output;
curl_close($ch);
When I execute this application (client/server), I got this output:
HTTP/1.1 100 Continue
Client 16: msg 'POST / HTTP/1.1
Host: 192.168.1.110:10000
Accept: */*
Content-Length: 52
Content-Type: application/x-www-form-urlencoded
ASERIAL_NUMBER =123456&HARDWARE_ID =455FFG&CODE =99&1HTTP/1.1 100 Continue
Client 17: msg 'POST / HTTP/1.1
Host: 192.168.1.110:10000
Accept: */*
Content-Length: 25
Content-Type: application/x-www-form-urlencoded
test second session !!!!!
The problem is that the HTTP client doesn't send the data in the same session, the client number was incremented [Client 16, Client 17]!!
How to send the data in the same session using Curl?
The session is stored in the cookie of your browser:
When you make a server-side Curl request (like in your PHP code) that cookie isn't being replicated.
What you need to do is tell Curl to include a cookie header. You get the current cookie from the $_COOKIE array and place it into headers that you send along with the Curl request.
$headers = array();
// Add cookies to headers, if they're present
if( isset($_COOKIE) === true
&& is_array($_COOKIE) === true
&& sizeof($_COOKIE) > 0
) {
$cookie_header = "Cookie:";
// Concatenate each cookie key and value like "key=value"
foreach($_COOKIE as $k=>$v) {
$cookie_header .= " ".safestring($k)."=".safestring($v).";";
}
$headers[] = $cookie_header;
}
// Add headers to request, if they're present
if(sizeof($headers) > 0) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
I am sending post request on php and after post i want to show thank you message
my post code is:
<?php
$error = '';
$FullName = $_POST['FullName'];
$Email = $_POST['Email'];
$Password = $_POST['Password'];
$Content = $FullName." ".$Email." ".$Password;
$server= '192.168.1.13:3033';
$path = '/user/registration';
$headers= "POST $path HTTP/1.0\r\nContent-type: text/html\r\nHost: $server\r\nContent-length: $Content\r\n\r\n";
$fp = fsockopen($server, $port);
if (!$fp) return false;
fputs($fp, $headers);
fputs($fp, $Content);
$ret = "";
while (!feof($fp)) {
$ret.= fgets($fp, 1024);
}
fclose($fp);
print $ret;
?>
my post request is working but i do not how to display message on the same page
Any help will be appreciated
I'm not sure what you are trying to do here but you could give a try to the following and let me know
<?php
$port = 3033;
$error = '';
$FullName = $_POST['FullName'];
$Email = $_POST['Email'];
$Password = $_POST['Password'];
$Content = $FullName." ".$Email." ".$Password;
$server= '192.168.1.13';
$path = '/user/registration';
$headers = "POST $path HTTP/1.0\r\nContent-type: text/html\r\nHost: $server\r\nContent-length: $Content\r\n\r\n";
$data = $headers . $Content;
$fp = fsockopen($server, $port);
if (!$fp)
{
return false;
}
else
{
fputs($fp, $data);
$ret = "";
while (!feof($fp)) {
$ret.= fgets($fp, 1024);
}
fclose($fp);
print("Thank you for using our service.\r\n\r\n".$ret);
}
?>
The echo function might be of interest here.