0

Hi All,
I have a PHP code for Sending http post from cURL. it work fine but i have a trouble that when i am send any data from loop it display me only first string the remaining string it not print.
I am Use this Code.

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Send Group SMS to Your all Clients.</title>
<LINK 
href="styles/changepw.css" 
type=text/css rel=stylesheet>
<LINK rel="stylesheet" href="styles/ui.tabs.css" type="text/css" media="print, projection, screen">
<SCRIPT src="js/jquery-1.2.6.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/ui.core.js" type="text/javascript"></SCRIPT>
<SCRIPT src="js/ui.tabs.js" type="text/javascript"></SCRIPT>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="100%"><h2>Send Group SMS</h2>
    <p align="justify"><font size="2">To Send SMS on any Desired Number Simply 
    Insert The Mobile Number witch u Want to Send SMS and Enter SMS Text What 
    You Want to Send and Click on Send SMS Button. Your SMS Will be Delivered to 
    Desired Number. You May Send Multiple SMS Simply Add Mobiles Number 
    Separated by Comma (,) and Enter SMS Text and Hit Send SMS Button to Send 
    SMS.</font><br/></td>
  </tr>
  <tr>
    <td width="100%">&nbsp;</td>
  </tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!-- Dynamic Version by: Nannette Thacker -->
<!-- [url]http://www.shiningstar.net[/url] -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
//  End -->
  </script>
  <form name="send_sms" method="POST">
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
    <tr>
      <td width="15%" align="right"><font size="2">Mobile Number(s)</font></td>
      <td width="2%" align="center"><font size="2">:</font></td>
      <td width="83%">
      <INPUT class="text" name="mobile_no" maxlength="50" size="52"></td>
    </tr>
    <tr>
      <td width="15%" align="right"><div style="width: 147; height: 99"><font size="2">Message</font></div></td>
      <td width="2%" align="center"><div style="width: 19; height: 101">:</div></td>
      <td width="83%"><textarea rows="6" name="message" class="textarea" id="textarea" wrap="physical" onKeyDown="textCounter(document.send_sms.message,document.send_sms.remLen1,160)"
onKeyUp="textCounter(document.send_sms.message,document.send_sms.remLen1,160)" cols="34" maxlength="160"></textarea></td>
    </tr>
    <tr>
      <td width="15%" align="right">&nbsp;</td>
      <td width="2%" align="center">&nbsp;</td>
      <td width="83%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<input readonly type="text" name="remLen1" size="3" maxlength="3" value="160">
      <font size="2">Character Left</font></td>
    </tr>
    <tr>
      <td width="15%" align="right">&nbsp;</td>
      <td width="2%" align="center">&nbsp;</td>
      <td width="83%">
      <INPUT type="submit" class="button" name="submit" value="Send SMS"> 
      <INPUT type="reset" class="button" value="Cancel"></td>
    </tr>
  </table>
</form>
</body>

</html>
<?php
if (isset($_POST['submit']))
{
$message = $_POST['message']; //POST message
$number = $_POST['mobile_no']; //POST number
$numbers = explode(",", $number); //Explode Number with (,)
for ($i=0; $i < count($numbers); $i++)
{
    /** 
     * Define POST URL and also payload
     */
    define('XML_PAYLOAD', "<?xml version='1.0' encoding='ISO-8859-1' ?>
<push>
<from>user_id$api_key</from>
<gsm>SAMPLE</gsm>
<cdma>9876543210</cdma>
<message>$message</message>
<mobileno>
<nos>$numbers[$i]</nos>
</mobileno>
</push>");

    define('XML_POST_URL', 'http://api.znisms.com/post/xmlsmsv3.asp');
        
    /**
     * Initialize handle and set options
     */
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, XML_POST_URL); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
    
    /**
     * Execute the request and also time the transaction
     */
    $start = array_sum(explode(' ', microtime()));
    $result = curl_exec($ch); 
    $stop = array_sum(explode(' ', microtime()));
    $totalTime = $stop - $start;
    
    /**
     * Check for errors
     */
    if ( curl_errno($ch) ) {
        $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
    } else {
        $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        switch($returnCode){
            case 404:
                $result = 'ERROR -> 404 Not Found';
                break;
            default:
                break;
        }
    }
    
    /**
     * Close the handle
     */
    curl_close($ch);
    
    /**
     * Output the results and time
     */
    echo 'Total time for request: ' . $totalTime . "\n";
    echo $result;
	   
	}
	}
?>

This only send first string to server the all explode string not sending by it.
Please Help Me.
I Hope Your Understand The above Statement witch i want to Say because i am not expert in english.

Thanx...

2
Contributors
13
Replies
16
Views
7 Years
Discussion Span
Last Post by hemgoyal_1990
0

I have just checked+tested your script and your for loop works perfectly. However the 2 breaks; in your switch command may be prevent the for loop from working. I would suggest finding an alternative to using the switch command.

0

I have just checked+tested your script and your for loop works perfectly. However the 2 breaks; in your switch command may be prevent the for loop from working. I would suggest finding an alternative to using the switch command.

Could u provide me the alternative for using for loop perfectly?
Please Help me Out.

0

What does $returnCode actually contain?

$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        switch($returnCode){
            case 404:
                $result = 'ERROR -> 404 Not Found';
                break;
            default:
                break;
        }

I would suggest replacing the above with the below if it just has a number.

$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($returnCode==404 || $returnCode=='404'){
                $result = 'ERROR -> 404 Not Found';
        }
0

The $returnCode will Return The Message Follow:
Total time for request: 0.308465003967 XXXXXXXXXX3738246550#Messages Sent1

0

If it returns the following and never returns 404 then that would make the switch statement useless.

Total time for request: 0.308465003967 XXXXXXXXXX3738246550#Messages Sent1

So I would suggest trying what I suggested in my previous post as it should work.

0

If it returns the following and never returns 404 then that would make the switch statement useless.

Total time for request: 0.308465003967 XXXXXXXXXX3738246550#Messages Sent1

So I would suggest trying what I suggested in my previous post as it should work.

I am Try Your above suggestion but my problem not solved.
and also this never return '404 Error' because this is an SMS getway application.

0

I tested it and it worked in my tests but worked too well. It only reports 404 errors and if you got a 500 error then it would not be reported.

$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        switch($returnCode){
            case 404:
                $result = 'ERROR -> 404 Not Found';
                break;
            default:
                break;
        }

Replace the above with the below:

$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($returnCode!==200 || $returnCode!=='200'){
                $result = 'ERROR -> Status '.$returnCode;
        }
0

When i am Try your suggest above code then it give me below error:

Total time for request: 0.225823163986 ERROR -> Status 200

0

Weird. Should have worked. :?:
Below is another piece of code you can try and hopefully it should work.

$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($returnCode!=='200' || $returnCode!==200 ||$returnCode>200 || $returnCode<200
|| $returnCode!==(int)200 ||$returnCode>(int)200 || $returnCode<(int)200){
                $result = 'ERROR -> Status '.$returnCode;
        }
0

The above Return Same Error..
But my problem is another that i am sending array from for loop but it only send first string of my explode string not accept all string in XML document.
but if i try this in whole page it will work.
what is the problem it erectly.
please help me.
thanx...

0

I believe it is the break; code in the switch statement. That is why I suggested replacing it with an if statement. But obviousley there is something fishy going on with the $returnCode variable.

0

i am complitly remove the error handling code.
but this is not work. it only send sms to first number give any number.
am replace my code to another one script....

<?php
if (isset($_POST['submit']))
{
$message = $_POST['message'];
$number = $_POST['mobile_no'];
$numbers = explode(",", $number);
$i = 0;
while ($i < count($numbers))
{
	 // XML data as string 
$request = "<?xml version='1.0' encoding='ISO-8859-1' ?>"; 
$request .= "<push>"; 
$request .= "<from>test$apikey</from>"; 
$request .= "<gsm>TEST</gsm>"; 
$request .= "<cdma>9876543210</cdma>"; 
$request .= "<message>$message</message>"; 
$request .= "<mobileno>"; 
$request .= "<nos>$numbers[$i]</nos>"; 
$request .= "</mobileno>";
$request .= "</push>";

// Create Headers 
$header[] = "Host: www.example.com"; 
$header[] = "Content-type: text/xml"; 
$header[] = "Content-length: ".strlen($request) . "\r\n"; 
$header[] = $request;

// Send using CURL 
$ch = curl_init(); 
curl_setopt( $ch, CURLOPT_URL, "http://api.znisms.com/post/xmlsmsv3.asp"); // URL to post 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable 
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above 
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); // special POST with specified Content-type 
$result = curl_exec( $ch ); // runs the post 
curl_close($ch);

echo $result; // echo reply response
	$i++;
	   
	}
	}
?>

But it not provide me any result.
please Help me Out..

or please Suggest me any other script so i can run my script.

0

Dear Friend,
I am Solved out My Problem.
Thank You for Helping me Out.
Now I am Mark This Thread as Solved.

Thanx Again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.