0

I have a PHP library that I have downloaded - it is a popular library that is used on a lot of sites. I run this locally on my localhost and all ok. I then tried to load it to website and run it there and getting a parse error.

I cant work out why it runs on my localhost and not on website - can you please take a look and see if it is something obvious ? maybe php.ini setting I need to set or something else ?

The error is

Parse error: syntax error, unexpected '[' in /home/phoenixs/public_html/smsGateway.php on line 14

Here is the library and I have highlighted line 14.:

line 14 is return $this->makeRequest('/api/v3/contacts/create','POST',['name' => $name, 'number' => $number]);

  • I have put the calling script below this

    class SmsGateway { static $baseUrl = "https://smsgateway.me"; function __construct($email,$password) { $this->email = $email; $this->password = $password; } function createContact ($name,$number) { return $this->makeRequest('/api/v3/contacts/create','POST',['name' => $name, 'number' => $number]); } function getContacts ($page=1) { return $this->makeRequest('/api/v3/contacts','GET',['page' => $page]); } function getContact ($id) { return $this->makeRequest('/api/v3/contacts/view/'.$id,'GET'); } function getDevices ($page=1) { return $this->makeRequest('/api/v3/devices','GET',['page' => $page]); } function getDevice ($id) { return $this->makeRequest('/api/v3/devices/view/'.$id,'GET'); } function getMessages($page=1) { return $this->makeRequest('/api/v3/messages','GET',['page' => $page]); } function getMessage($id) { return $this->makeRequest('/api/v3/messages/view/'.$id,'GET'); } function sendMessageToNumber($to, $message, $device, $options=[]) { $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST',$query); } function sendMessageToManyNumbers ($to, $message, $device, $options=[]) { $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendMessageToContact ($to, $message, $device, $options=[]) { $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendMessageToManyContacts ($to, $message, $device, $options=[]) { $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendManyMessages ($data) { $query['data'] = $data; return $this->makeRequest('/api/v3/messages/send','POST', $query); } private function makeRequest ($url, $method, $fields=[]) { $fields['email'] = $this->email; $fields['password'] = $this->password; $url = smsGateway::$baseUrl.$url; $fieldsString = http_build_query($fields); $ch = curl_init(); if($method == 'POST') { curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString); } else { $url .= '?'.$fieldsString; } curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER , false); // we want headers curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec ($ch); $return['response'] = json_decode($result,true); if($return['response'] == false) $return['response'] = $result; $return['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close ($ch); return $return; } } ?>

and here is the calling script:

  <?php


include "smsGateway.php";

$smsGateway = new SmsGateway('user', 'password');

$deviceID = 22233;

$number = '+64210419805';
$message = 'hi gg 3';

$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID);

print_r($result);

?>
Roger Russel
  • 714
  • 7
  • 17
dkmarsh
  • 29
  • 6
  • 2
    What version of PHP are you running on your website server? Short array syntax requires PHP >= 5.4.0 – Mark Baker May 19 '16 at 21:45
  • Thank you so much Mark - it was PHP 5.3 and updated it so all working now. I really appreciate your help. – dkmarsh May 19 '16 at 22:02

0 Answers0