While loop not running after function - php

I have a while loop that checks my database for notifications with a status of 1. It then sends a notification to OneSignal.com's API so the user will get the notification.
The problem is, I'm trying to run the script so that it processes all records with a status of 1 as it makes the while loop, but once I include the function for OneSignal the while loop stops after processing only one record.
I cant figure it out, I tried moving things around, and when I put the send message function outside the while loop, the php variables for the user ID don't get passed to it?
What should I do?
<?php
require('connection.inc.php');
$notification = mysqli_query($con, "SELECT *, t1.id AS NotifID FROM notification AS t1 LEFT JOIN user AS t2 ON t1.action_user_id = t2.id WHERE status = '1' ORDER BY time_updated DESC") or die(mysql_error());
//GET NOTIFCATION RECORD
while ($row = mysqli_fetch_assoc($notification)) {
$notificationID = $row['NotifID'];
$type = $row['notification_type'];
$action_user_id = $row['action_user_id'];
$action_user_name = $row['name'];
$action_user_profile = empty($row['profile_image']) ? '/instachurch/images/profile/profile.png' : '/instachurch/' . $row['profile_image'];
$time = $row['time_updated'];
$post_id = $row['post_id'];
$notify_user_id = $row['notify_user_id'];
// GET NOTIFY USER INFO
$GetUserName = mysqli_query($con, "SELECT * FROM user WHERE id = $notify_user_id ") or die(mysql_error());
while ($row = mysqli_fetch_assoc($GetUserName)) {
$username = $row['name'];
$userMob = $row['mob'];
$userHash = $row['hash'];
$OneSignalPushID = $row['id'];
if ($type == "post_liked")
$message = $action_user_name . " liked your post.";
else if ($type == "post_comment")
$message = $action_user_name . " commented on your post.";
else if ($type == "post_comment_reply")
$message = $action_user_name . " replied to your comment.";
else if ($type == "post_answer")
$message = $action_user_name . " answered to your question.";
else if ($type == "follow_user")
$message = $action_user_name . " started following you.";
else if ($type == "discussion_topic_comment")
$message = $action_user_name . " commented on your forum topic.";
else if ($type == "timeline_mention")
$message = $action_user_name . " mentioned you in a comment.";
else if ($type == "school_lesson_mention" || $type == "school_discussion_mention")
$message = $action_user_name . " mentioned you in a comment on discussion.";
if ($type == "post_comment" || $type == "post_liked" || $type == "post_comment_reply" || $type == "post_answer" || $type == "timeline_mention")
$link = "http://www.gypsychristiannetwork.com/instachurch/post.php?post_id=" . $post_id . '&hash=' . $userHash;
else if ($type == "follow_user")
$link = "http://www.gypsychristiannetwork.com/instachurch/users.php?id=" . $action_user_id . '&hash=' . $userHash;
else if ($type == "discussion_topic_comment")
$link = "http://www.gypsychristiannetwork.com/tgcm/school/account.php?q=24&topic=" . $post_id . '&hash=' . $userHash;
else if ($type == "school_lesson_mention")
$link = "http://www.gypsychristiannetwork.com/tgcm/school/account.php?q=11&qid=" . $post_id . '&hash=' . $userHash;
else if ($type == "school_discussion_mention")
$link = "http://www.gypsychristiannetwork.com/tgcm/school/account.php?q=24&topic=" . $post_id . '&hash=' . $userHash;
}
$q3 = mysqli_query($con, "UPDATE `notification` SET `status` = '2' WHERE `id` = '$notificationID'");
echo $notificationID . ':' . $message;
// echo $link;
$userPushID = $OneSignalPushID;
// echo $userPushID.'<BR><P>';
$heading = 'Check your Notifications';
$content = array(
"en" => $message
);
$heading = array(
"en" => $heading
);
$fields = array(
'app_id' => "APPID",
'include_external_user_ids' => array(
"$userPushID"
),
'channel_for_external_user_ids' => 'push',
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $heading,
'url' => $link
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic APPSECRET'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode($return);
print("\n\nJSON received:\n");
print($return);
print("\n");
}
?>

There seems to be a 'return $response' line near the bottom, which would probably break the while{}. Try removing that, or maybe rewrite that part

Well, if it were me, I would try to rework this first so there are fewer nested while loops. In this case, you can do it fairly simply, by iterating through the results (as you're doing) and pushing them to an array outside the function, like so:
$ary = array();
while($row = mysqli_fetch_array($yourQueryResults, MYSQLI_ASSOC))
{
array_push($ary, array($row['valueYouIntendToUseLater']));
}
Then you can run the interior while on the resulting array, like
foreach($element in $ary){
while.....etc
}
And so on. You get the drill. While this format is certainly not necessary, it does make debugging easier in my experience. As #Jelmer pointed out, the reason this while function is biting the dust is because you're calling return in it, which breaks the loop, as is its purpose.

Related

file_get_contents HTTP request failed error

So I have GetMessages.php, this script gets data out of an database(MongoDB). Then it makes a cURL POST to MyMessagesMDB.php. This is the code:
<?php
$FirstName = '';
$LastName = '';
$Email = '';
$Subject = '';
$Message = '';
GetFromDB();
echo $FirstName." ".$LastName;
echo "<br>";
echo $Email;
echo "<br>";
echo $Subject;
echo "<br>";
echo $Message;
echo "<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.0.163/MyMessagesMDB.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"FirstName=$FirstName&LastName=$LastName&Email=$Email&Subject=$Subject&TextMessage=$Message");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
function GetFromDB(){
$client = new MongoDB\Driver\Manager('mongodb+srv://####:#########.tldyu.mongodb.net/Data');
$filter = [];
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $client->executeQuery('ContactMessages.ContactForm', $query);
foreach($cursor as $document){
$document = json_decode(json_encode($document),true);
global $FirstName, $LastName, $Email, $Subject, $Message;
$FirstName = $document['FirstName'];
$LastName = $document['LastName'];
$Email = $document['Email'];
$Subject = $document['Subject'];
$Message = $document['Message'];
}
}
?>
MyMessagesMDB.php is the script to get called first. It calls GetMessages.php and should then receive the information it has posted. Here is the code:
<?php
$FirstLoop = true;
if($FirstLoop == true){
file_get_contents('http://192.168.0.102/test/GetMessages.php');
$FirstLoop = false;
}
$FirstName = $_POST["FirstName"] ?? "";
$LastName = $_POST["LastName"] ?? "";
$Email = $_POST["Email"] ?? "";
$Subject = $_POST["Subject"] ?? "";
$Message = $_POST["TextMessage"] ?? "";
echo $FirstName." ".$LastName;
echo "<br>";
echo $Email;
echo "<br>";
echo $Subject;
echo "<br>";
echo $Message;
echo "<br>";
?>
But here starts my problem.
If I call MyMessagesMDB.php I get the error:
PHP Warning: file_get_contents(http://192.168.0.102/test/GetMessages.php): Failed to open stream: HTTP request failed!.
If I try to load the page manually I get no error and the data out of the database is printed on the screen.
When in MyMessagesMDB.php I comment the following line like this:
#file_get_contents('http://192.168.0.102/test/GetMessages.php');
I can load the page without any problem or error.
The Question
What do I have to do to call GetMessages.php from MyMessagesMDB.php and receive the information out of the database?
Note: I have tried
$curl_handle=curl_init();
curl_setopt($curl_handle,
CURLOPT_URL,'http://###.##.##.##/mp/get?
mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert
format=flv');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application
name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
After our comments back and forth, I think your implementation is way more complicated than it needs to be. Instead of MyMessagesMDB.php acting as both an initiator of the process and a recipient of data, it only needs to be an initiator.
In this implementation, mdb.php acts as the script that would sit with your database, it's whole job is to take everything from the ContactMessages.ContactForm query and output it as JSON.
<?php
$client = new MongoDB\Driver\Manager('mongodb+srv://####:#########.tldyu.mongodb.net/Data');
$filter = [];
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $client->executeQuery('ContactMessages.ContactForm', $query);
header('Content-Type: application/json');
echo json_encode($cursor);
Then you have get.php, which you have on the server at school, which uses file_get_contents to get the JSON, and then convert it back to a PHP array, which you can then output however you see fit.
<?php
$mdb_url = 'http://192.168.0.102/test/GetMessages.php';
$get = file_get_contents($mdb_url);
$decoded = json_decode($get, true);
foreach ($decoded as $document) {
echo $document['FirstName'] . '<br>' .
$document['LastName'] . '<br>' .
$document['Email'] . '<br>' .
$document['Subject'] . '<br>' .
$document['Message'] . '<br><hr>';
}

Can not send data to server with post request

i have 2 file.
file one.php:
<?php
include 'config/dbconnect.php';
$query = mysql_query("select * from getgift_logs where status = 1") or die(mysql_error());
echo("<table border='1'>");
echo("<tr>");
echo("<td>User ID</td>");
echo("<td>Yes</td>");
echo("</tr>");
while ($row = mysql_fetch_array($query)) {
echo("<tr>");
echo("<td>".$row['user_id']."</td>");
echo "<td><button class='yes' gift_id = '".$row['id']."'>Yes</button></td>";
echo("</tr>");
}
echo("</table>");
?>
<div id='result'></div>
<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$('.yes').click(function() {
var trans_id=$(this).attr("gift_id");
$.ajax({
url : "process.php?id="+trans_id,
type: "GET",
success: function(result) {
$('#result').html(result);
},
});
});
</script>
File one.php i send one get request to process.php file. And this is file process.php:
<?php
include("config/dbconnect.php");
date_default_timezone_set("UTC");
$id = $_POST['trans_id'];
$query = mysql_query("select * from getgift_logs where id = '".$id."'");
$row = mysql_fetch_array($query);
$topuplink = $row['topuplink'];
$trans_id = $row['trans_id'];
$clientsecret = $row['clientsecret'];
$accesstoken = $row['accesstoken'];
$lost_money = $row['lost_money'];
$status = $row['description'];
$time = date('Ymdhis',time());
$sign = md5($money."|".$trans_id."|".$time."|".$clientsecret);
$ch = curl_init();
$data = array(
'topup_money' => $lost_money,
'reference_trans_id' => $trans_id,
'description'=>$status,
'request_time'=> $time,
'sign'=>$sign
);
$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$url = $topuplink."".$accesstoken;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close ($ch);
?>
In process.php file i send POST REQUEST but it not work(It not send data to server).
I don't know i wrong something? Please, help me! Thank all!
Try this one
$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
rtrim($postvars , '&'); // remove last &
$url = $topuplink."".$accesstoken;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, count($data)); // count of total post fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close ($ch);

How do I process PHP in batches?

I using PHP to connect a MySQL DB and a 3rd party API. When using the following script I keep getting a timeout error. The owners of the API I'm using suggest limiting each call to 50 records. I'm new to PHP and despite all my Googling can't work out how to batch process. The script is as follows:
<?php
include('config.inc.php');
$conn = new mysqli($hostname, $username, $passwd, $db);
if ($conn->connect_error) {
echo 'Database connection failed...' . 'Error: ' . $conn->connect_errno . ' ' . $conn->connect_error;
exit;
} else {
$conn->set_charset('utf8');
}
$sql = "SELECT Duedate, Invoicenumber, customername, txndate, itemref_fullname, xeroaccountnumber, Description, Quantity, rate, XEROTAXTYPE FROM invoicelinedetail";
$rs = $conn->query($sql);
if ($rs == false) {
} else {
require('xeroconfig.php');
$XeroOAuth = new XeroOAuth(array_merge(array(
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures));
$initialCheck = $XeroOAuth->diagnostics();
$checkErrors = count($initialCheck);
if ($checkErrors > 0) {
// you could handle any config errors here, or keep on truckin if you like to live dangerously
foreach ($initialCheck as $check) {
echo 'Error: ' . $check . PHP_EOL;
}
} else {
$session = persistSession(array(
'oauth_token' => $XeroOAuth->config ['consumer_key'],
'oauth_token_secret' => $XeroOAuth->config ['shared_secret'],
'oauth_session_handle' => ''
));
$oauthSession = retrieveSession();
if (isset($oauthSession ['oauth_token'])) {
$XeroOAuth->config ['access_token'] = $oauthSession ['oauth_token'];
$XeroOAuth->config ['access_token_secret'] = $oauthSession ['oauth_token_secret'];
$xml = "<Invoices>\n";
foreach ($rs as $row) {
$xml .= "<Invoice>\n";
$xml .= "<Type>ACCREC</Type>\n";
$xml .= "<Contact>\n";
$xml .= "<Name>" . xmlEscape($row['customername']) . "</Name>\n";
$xml .= "</Contact>\n";
$xml .= "<Date>" . xmlEscape($row['txndate']) . "</Date>\n";
$xml .= "<DueDate>" . xmlEscape($row['Duedate']) . "</DueDate>\n";
$xml .= "</Invoice>\n";
}
$xml .= "</Invoices>";
#echo $xml;
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->invoices[0]) . " invoice created/updated in this Xero organisation.";
if (count($invoice->Invoices[0]) > 0) {
echo "The first one is: </br>";
pr($Invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
}
}
}
You case use the % operator to make a request every 50 invoices. Something like this (you may have to change count($rs) to something else depending on what type of object it is).
<?php
include('config.inc.php');
$conn = new mysqli($hostname, $username, $passwd, $db);
if ($conn->connect_error) {
echo 'Database connection failed...' . 'Error: ' . $conn->connect_errno . ' ' . $conn->connect_error;
exit;
} else {
$conn->set_charset('utf8');
}
$sql = "SELECT Duedate, Invoicenumber, customername, txndate, itemref_fullname, xeroaccountnumber, Description, Quantity, rate, XEROTAXTYPE FROM invoicelinedetail";
$rs = $conn->query($sql);
if ($rs == false) {
} else {
require('xeroconfig.php');
$XeroOAuth = new XeroOAuth(array_merge(array(
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures));
$initialCheck = $XeroOAuth->diagnostics();
$checkErrors = count($initialCheck);
if ($checkErrors > 0) {
// you could handle any config errors here, or keep on truckin if you like to live dangerously
foreach ($initialCheck as $check) {
echo 'Error: ' . $check . PHP_EOL;
}
} else {
$session = persistSession(array(
'oauth_token' => $XeroOAuth->config ['consumer_key'],
'oauth_token_secret' => $XeroOAuth->config ['shared_secret'],
'oauth_session_handle' => ''
));
$oauthSession = retrieveSession();
if (isset($oauthSession ['oauth_token'])) {
$XeroOAuth->config ['access_token'] = $oauthSession ['oauth_token'];
$XeroOAuth->config ['access_token_secret'] = $oauthSession ['oauth_token_secret'];
$invoice_counter = 0;
foreach ($rs as $row) {
if(++$invoice_counter % 50 === 1) {
$xml = "<Invoices>\n";
}
$xml .= "<Invoice>\n";
$xml .= "<Type>ACCREC</Type>\n";
$xml .= "<Contact>\n";
$xml .= "<Name>" . xmlEscape($row['customername']) . "</Name>\n";
$xml .= "</Contact>\n";
$xml .= "<Date>" . xmlEscape($row['txndate']) . "</Date>\n";
$xml .= "<DueDate>" . xmlEscape($row['Duedate']) . "</DueDate>\n";
$xml .= "</Invoice>\n";
if($invoice_counter % 50 === 0 || $invoice_counter == count($rs)) {
$xml .= "</Invoices>\n";
#echo $xml;
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml);
if ($XeroOAuth->response['code'] == 200) {
$invoice = $XeroOAuth->parseResponse($XeroOAuth->response['response'], $XeroOAuth->response['format']);
echo "" . count($invoice->invoices[0]) . " invoice created/updated in this Xero organisation.";
if (count($invoice->Invoices[0]) > 0) {
echo "The first one is: </br>";
pr($Invoice->Invoices[0]->Invoice);
}
} else {
outputError($XeroOAuth);
}
}
}
}
}
}

assigning mysql array result to php variable

I am trying to send sms to all the members in a mysql table using API.
I am able to send the sms.
But only first row in the table is being used, whereas I want that the sms is sent to all the records in the table.
The code I am using is like this:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$result = mysql_query("SELECT name,mobile FROM members");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$mobile=$row[1];
$name=$row[0];
$request = "";
$param['mobileno'] = "91". $mobile;
$param['message'] = "Dear $name (organisation name) wishes you a very very Happy Birthday";
$param['username'] = "username";
$param['password'] = "password";
$param['sendername'] = "sender";
foreach ($param as $key => $val ){$request .= $key . "=" . urlencode($val);
$request .= "&";}$request = substr( $request, 0, strlen( $request ) - 1 );
$url = "http://smsapi" . $request;
$ch = curl_init($url);curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
var_dump($result);exit;
curl_close( $ch );
I have modified the code as per the suggestions in the answers, but I am still getting the result for the first row only.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$result = mysql_query("SELECT name,mobile FROM members");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($row = mysql_fetch_row($result)) {
$mobile=$row[1];
$name=$row[0];
$request = "";
$param['mobileno'] = "91". $mobile;
$param['message'] = "Dear $name (organisation name) wishes you a very very Happy Birthday";
$param['username'] = "username";
$param['password'] = "password";
$param['sendername'] = "sender";
foreach ($param as $key => $val ){$request .= $key . "=" . urlencode($val);
$request .= "&";}$request = substr( $request, 0, strlen( $request ) - 1 );
$url = "http://smsapi" . $request;
$ch = curl_init($url);curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
var_dump($result);exit;
curl_close( $ch );
}
Use while($row = mysql_fetch_row($result)) to loop through the rows.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$result = mysql_query("SELECT name,mobile FROM members");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($row = mysql_fetch_row($result)) {
$mobile=$row[1];
$name=$row[0];
$request = "";
$param['mobileno'] = "91". $mobile;
$param['message'] = "Dear $name (organisation name) wishes you a very very Happy Birthday";
$param['username'] = "username";
$param['password'] = "password";
$param['sendername'] = "sender";
foreach ($param as $key => $val ){$request .= $key . "=" . urlencode($val);
$request .= "&";}$request = substr( $request, 0, strlen( $request ) - 1 );
$url = "http://smsapi" . $request;
$ch = curl_init($url);curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
var_dump($result);exit;
curl_close( $ch );
}
You need to loop all the rows.
something like:
while($row = mysql_fetch_row($result)) { .... }
also, the php mysql extension is deprecated, have a look at mysqli or pdo.
You're using mysql_fetch_row, which to my understanding only returns one row (if any is found). Consider using mysql_fetch_all instead

cURL and PHP displaying "1"

I have a PHP script with which I want to read servers from database and connect to them with cURL. Servers responds with results from sql query. The problem is that script after each respond from server displays number 1. The ouput looks like this:
Server 1: some results
1Server 2: some results
1Server 3: some results
1
Here is the code that reads servers from database and connects to them:
<?php
$mysql_id = mysql_connect('localhost', 'ms', 'pass');
mysql_select_db('servers', $mysql_id);
mysql_query("SET NAMES utf8");
$query = "SELECT * FROM svr";
$result = mysql_query($query);
$num = mysql_num_rows($result);
while ($data = mysql_fetch_assoc($result))
{
$server[] = $data;
}
mysql_close($mysql_id);
$i = 0;
while($i < $num) {
$dealer = $server[$i]['dealer'];
echo $dealer . "<br />";
$data = "val=a"; //just for testing
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/html; charset=utf-8')
);
$result = curl_exec($ch);
echo $result;
$i++;
}
?>
I discovered that 1 is displayed with "echo $result;" and the code for creating response is this:
<?php
$mysql_id1 = mysql_connect('localhost', 'ms', 'pass');
mysql_select_db('servers', $mysql_id1);
mysql_query("SET NAMES utf8");
$query2 = "SELECT * FROM data";
$result2 = mysql_query($query2);
$num2 = mysql_num_rows($result2);
while ($data2 = mysql_fetch_assoc($result2))
{
$deli[] = $data2;
}
$i1 = 0;
$space = " ";
while ($i1 < $num2) {
echo $space . $deli[$i1]['id'] . " ";
echo $deli[$i1]['artikel'] . " ";
echo $deli[$i1]['znamka'] . " ";
echo $deli[$i1]['model'] . " ";
echo $deli[$i1]['letnik'] . " ";
echo $deli[$i1]['cena'] . " € ";
echo $deli[$i1]['zaloga'] . "<br />";
$i1++;
}
echo "<br />";
mysql_close($mysql_id1);
?>
Please help me
Use the CURLOPT_RETURNTRANSFER option. Otherwise cURL will automatically echo the data and just return true (which is converted to 1 by echo).
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
PHP.net says,
TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.
You need to use CURLOPT_RETURNTRANSFE or curl_exec returns a statuscode and sends the response to stdout:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
CURLOPT_RETURNTRANSFER shoud be TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.read the full documentation php.net
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
or you can do
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Use CURLOPT_RETURNTRANSFE or else it will return a status-code and sends the response to stdout:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Man, if the user can change dealer field or $deli fields you have got stored XSS vulnerability here.
$dealer = $server[$i]['dealer'];
echo $dealer . "<br />";
echo $space . $deli[$i1]['id'] . " ";
...etc
use
htmlentities($your fields)
to solve this problem

Categories