简体   繁体   English

Twilio PHP脚本在远程服务器上返回代码500错误,在本地服务器上工作正常吗?

[英]Twilio PHP script returning code 500 error when on remote server, working fine on local server?

I have the following PHP script to send a verification text using Twilio: 我有以下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);
?>

When I run it using http://localhost/sms.php?num=01115465467&country=Egypt and I change the directory for the autoload.php file to /Applications/XAMPP/xamppfiles/htdocs/twilio-php-master/Twilio/autoload.php (where it is installed on my computer), the script works fine. 当我使用http://localhost/sms.php?num = 01115465467&country = Egypt运行它时,我将autoload.php文件的目录更改为/ Applications / XAMPP / xamppfiles / htdocs / twilio-php-master / Twilio / autoload .php(在我的计算机上安装的位置),脚本可以正常工作。 However, I uploaded it to a remote server, and tried using the directory /var/www/html/group1/twilio-php-master/autoload.php (where it is on the server) and running it on http://188.226.144.157/group1/sms.php?num=01115465467&country=Egypt , but my android app returns an error code of 500 when it tries to run the script. 但是,我将其上传到远程服务器,并尝试使用目录/var/www/html/group1/twilio-php-master/autoload.php(在服务器上),并在http://188.226上运行.144.157 / group1 / sms.php?num = 01115465467&country = Egypt ,但是我的Android应用尝试运行脚本时返回错误代码500。

The URL you have entered for the file location on your server is wrong, you have missed a directory http://188.226.144.157/group1/twilio-php-master/autoload.php returns 404 您为服务器上的文件位置输入的URL错误,错过了目录http://188.226.144.157/group1/twilio-php-master/autoload.php返回404

Whereas this works http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php 而这有效http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM