PHP:服务器错误

PHP:服务器错误,php,android,mysql,Php,Android,Mysql,我有一个发送OTP的PHP代码,当我在本地服务器上执行它时,它工作得很好。但当我在通过更改主机名等将代码从本地更改为服务器后运行此代码时,我得到500个内部服务器错误。我不知道我错在哪里。任何解决方案都将受到重视。多谢各位 <?php include './include/DbHandler.php'; $db = new DbHandler(); $response = array(); // echo $_POST['mobile']; if (isset($_POST['mob

我有一个发送OTP的PHP代码,当我在本地服务器上执行它时,它工作得很好。但当我在通过更改主机名等将代码从本地更改为服务器后运行此代码时,我得到500个内部服务器错误。我不知道我错在哪里。任何解决方案都将受到重视。多谢各位

<?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);
    }


      ?>

我不认为500错误来自您的代码。这可能是Apache配置相关的问题。可能是上传了一个错误的.htaccess或php.ini,或者服务器上的Apache版本在语法上有误。

看看你在这里发布的内容,一切似乎都很好。这可能有很多原因。你的error.log文件是怎么写的?看看这个:,可能有助于了解为什么500.@amitsigh调用var/www/html/…中未定义的函数curl\u init()。这是我在错误日志中看到的,这意味着你的服务器没有启用curl扩展名。您需要在服务器的php.ini文件中启用curl扩展。谢谢@amitsigh,我会检查并还原您