-1

I have a PHP code for sending OTP, When i execute it in my local server its works well. But when i run this code after changing it from my local to server by changing host name etc, i am getting 500 internal server error. I don't know where i am going wrong. Any solution will be apreciated. Thank you

<?php

include './include/DbHandler.php';
$db = new DbHandler();
$response = array();

// echo $_POST['mobile'];

if (isset($_POST['mobile']) && $_POST['mobile'] != '') {

$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];

 $otp = rand(100000, 999999);

 $res = $db->createUser($name, $email, $mobile, $otp);

 if ($res == USER_CREATED_SUCCESSFULLY) {

   // send sms
   sendSms($mobile, $otp);

   $response["error"] = false;
   $response["message"] = "SMS request is initiated! You will be receiving it shortly.";
 } else if ($res == USER_CREATE_FAILED) {
   $response["error"] = true;
   $response["message"] = "Sorry! Error occurred in registration.";
 } else if ($res == USER_ALREADY_EXISTED) {
   $response["error"] = true;
   $response["message"] = "Mobile number already existed!";
 }
} else {
 $response["error"] = true;
 $response["message"] = "Sorry! mobile number is not valid or missing.";
}

echo json_encode($response);

 function sendSms($mobile, $otp) {

   $otp_prefix = ':';

   //Your message to send, Add URL encoding here.
  $message = urlencode("Hello Your OPT is '$otp_prefix $otp'");

  $response_type = 'json';

 //Define route 
  $route = "4";

   //Prepare you post parameters
    $postData = array(
     'authkey' => AUTH_KEY,
     'mobiles' => $mobile,
   'message' => $message,
   'sender' => SENDER_ID,
   'route' => $route,
   'response' => $response_type
   );

//API URL
  $url = "https://control.otp.com/sendhttp.php";

 // init the resource
  $ch = curl_init();
   curl_setopt_array($ch, array(
   CURLOPT_URL => $url,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_POST => true,
   CURLOPT_POSTFIELDS => $postData
       //,CURLOPT_FOLLOWLOCATION => true
  ));


   //Ignore SSL certificate verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


    //get response
    $output = curl_exec($ch);

    //Print error if any
    if (curl_errno($ch)) {
     echo 'error:' . curl_error($ch);
    }

       curl_close($ch);
    }


      ?>
ram kumar
  • 187
  • 1
  • 1
  • 16
  • Looking at what you have posted here, everything seems to be fine.There can be a lot of reasons for that. What does your error.log file says? – Amit Singh Aug 11 '15 at 13:59
  • Have a look at this: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display , might be useful to know why the 500. –  Aug 11 '15 at 13:59
  • @AmitSingh Call to undefined funtion curl_init() in var/www/html/.......This is what i am getting in my error log – ram kumar Aug 11 '15 at 14:04
  • 2
    That means your server do not have curl extension enabled. You need to enable the curl ectension in php.ini file of your server. – Amit Singh Aug 11 '15 at 14:05
  • Thanks @AmitSingh I will check and will revert you – ram kumar Aug 11 '15 at 14:07

1 Answers1

0

I dont think the 500 error comes from your code. That's likely an Apache config related problem. Possibly a stray .htaccess or php.ini got uploaded, or is syntactically wrong for the version of Apache you have on the server.

Duane Lortie
  • 1,285
  • 1
  • 12
  • 16