【问题标题】:Twilio PHP script returning code 500 error when on remote server, working fine on local server?Twilio PHP脚本在远程服务器上返回代码500错误,在本地服务器上工作正常?
【发布时间】:2017-07-03 20:34:10
【问题描述】:

我有以下 PHP 脚本来使用 Twilio 发送验证文本:

<?php

require '/twilio-php-master/Twilio/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;


$AccountSid = "xxx"; // Your Account SID from www.twilio.com/console

$AuthToken = "xxx";   // Your Auth Token from www.twilio.com/console

$client = new Client($AccountSid, $AuthToken);
$number = $_GET['num'];
$country = $_GET['country'];
$receivingPhone = "+2".$number;
$code = rand(100000, 999999);

$client->messages->create(
// the number you'd like to send the message to
$receivingPhone,
array(
    // A Twilio phone number you purchased at twilio.com/console
    'from' => '+12562947081',
    // the body of the text message you'd like to send
    'body' => $code
)
);
     $object = new stdClass();
     $object->num = $code;
     echo json_encode($object);
?>

当我使用 http://localhost/sms.php?num=01115465467&country=Egypt 运行它并将 autoload.php 文件的目录更改为 /Applications/XAMPP/xamppfiles/htdocs/twilio-php-master/Twilio/autoload.php (它安装在我的计算机),脚本工作正常。但是,我将它上传到远程服务器,并尝试使用目录 /var/www/html/group1/twilio-php-master/autoload.php (它在服务器上)并在http://188.226.144.157/group1/sms.php?num=01115465467&country=Egypt 上运行它,但是我的 android 应用在尝试运行脚本时返回错误代码 500。

【问题讨论】:

    标签: php twilio twilio-php


    【解决方案1】:

    您为服务器上的文件位置输入的 URL 错误,您错过了一个目录 http://188.226.144.157/group1/twilio-php-master/autoload.php 返回 404

    虽然这行得通 http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php

    试试这个
    require '/var/www/html/group1/twilio-php-master/Twilio/autoload.php'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      • 2015-11-13
      • 2011-07-26
      相关资源
      最近更新 更多