0

I have trouble sending data from remote server to a web server at hosting company. At remote server the cURL execute perfectly without any error, but in database at web server doesn't seem receive any data. I don't really know what or why this is happen. I've try to contact my hosting company for explanation and they said the server already support cURL lib. Can someone help me with this.

send.php (runs in remote server)

<?php

$number= '12345';
$status= 'SUCCESS';
$msg = 'Transaction is Success!';

$curlHandle         = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, 'http://mywebsite.org/update.php');
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'number='.$number.'&status='.$status.'&msg ='.$msg);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);

if (!curl_exec($curlHandle)) {
    echo 'An error has occurred: ' . curl_error($curlHandle);
}
else {
    echo 'everything was successful';
}   

curl_close($curlHandle);

?>

update.php (runs in web server)

<?php
include ("db_con.php");

$number = $_POST['number'];
$status = $_POST['status'];
$msg = $_POST['msg '];

$query  = "UPDATE tbstatus SET status = '$status', msg = '$msg '  WHERE number = '$number '";
mysql_query($query);

?>

Thank you in advance.

4
  • and for addition I've try to echo curl_getinfo($curlHandle, CURLINFO_HTTP_CODE); and the return is 301. Commented Apr 23, 2014 at 5:20
  • Can you try - print_r($_POST); exit; in your update.php .....and then echo curl_exec($curlHandle); in send.php? What does it written? Commented Apr 23, 2014 at 5:30
  • @RajSf it return something like this HTTP/1.1 301 Moved Permanently Date: Wed, 23 Apr 2014 05:32:50 GMT Server: Apache Location: http://www.mywebsite.org/update.php Content-Length: 247 Content-Type: text/html; charset=iso-8859-1. Commented Apr 23, 2014 at 5:35
  • Also in the browser it says Moved Permanently The document has moved here. I don't know what it means. when I clicked it I've redirected to empty update.php Commented Apr 23, 2014 at 5:42

2 Answers 2

1

Most of the sites using the rewrite rule to remove the www

Can you try removing www from the url?

Also set

curl_setopt($curlHandle,CURLOPT_FOLLOWLOCATION,true);

If this won't work then -

In your php.ini - set safe_mode = Off, if that is already off then comment open_basedir

and then restart the web server.

Sign up to request clarification or add additional context in comments.

5 Comments

yes. but the result not the way I expected. i'got this respond from server in browser HTTP/1.1 301 Moved Permanently Date: Wed, 23 Apr 2014 05:47:36 GMT Server: Apache Location: http://www.mywebsite.org/update.php Content-Length: 247 Content-Type: text/html; charset=iso-8859-1 HTTP/1.1 200 OK Date: Wed, 23 Apr 2014 05:47:37 GMT Server: Apache X-Powered-By: PHP/5.3.19 Content-Length: 0 Content-Type: text/html
I've change the url from curl_setopt($curlHandle, CURLOPT_URL, 'http://mywebsite.org/update.php'); to curl_setopt($curlHandle, CURLOPT_URL, 'mywebsite.org/update.php'); but nothing happened in database.
CURL_FOLLOWLOCATION cannot be activated when safe_mode or openbase_dir is set - check with the above settings ( answer updated )
sorry for the late respond I'm on wifi with bad internet connection. I've check out the php.ini and both already done. safe mode already off and open basedir is already commented.
0

Try this instead:

send.php

<?php

$number= '12345';
$status= 'SUCCESS';
$msg = 'Transaction is Success!';

$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, 'http://mywebsite.org/update.php');
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'number='.$number.'&status='.$status.'&msg ='.$msg);
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);

if (!curl_exec($curlHandle)) {
    echo 'An error has occurred: ' . curl_error($curlHandle);
}
else {
    echo 'everything was successful';
}   

curl_close($curlHandle);

?>

update.php

<?php
include ("db_con.php");

$number = $_POST['number'];
$status = $_POST['status'];
$msg = $_POST['msg '];

$query  = "UPDATE tbstatus SET `status` = '$status', `msg` = '$msg'  WHERE `number` = '$number'";
mysql_query($query);

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.