Additional value 1 is added with a swirl.

From the following two files, I get the output (2000)1 , but it should only (2000)

After getting the value with curl extra 1 is added, but why?

balance.php

 <?php $url = "http://localhost/sms/app/user_balance.php"; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, 2); curl_setopt($ch,CURLOPT_POSTFIELDS, "id=2&status=Y"); $result = curl_exec($ch); curl_close($ch); echo $result; ?> 

user_balance.php

 <?php $conn = mysql_connect("localhost","root",""); mysql_select_db("sms",$conn); $user_id = $_REQUEST["id"]; $sql = "SELECT * FROM user_sms WHERE user_id='$user_id'"; $rec = mysql_query($sql); if($row = mysql_fetch_array($rec)) { $balance = $row["user_sms_balance"]; } echo "(".$balance.")"; ?> 
+7
php curl
source share
1 answer

In the PHP documentation for curl_setopt() :

CURLOPT_RETURNTRANSFER - set to TRUE to return the transfer as a string of the curl_exec () return value, rather than directly output it.

If you do not set the CURLOPT_RETURNTRANSFER parameter to TRUE , then the return value from curl_exec() will be the logical value of the operation - 1 or 0. To avoid this, you can set CURLOPT_RETURNTRANSFER to TRUE , as shown below:

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
+13
source share

All Articles