Hi i have a php script that create a new user account on my online backup server via a api, when i open in i.e or firefox i get this error message

Parse error: syntax error, unexpected $end in /home/public_html/123-backup.com/test.php on line 297

I' am not sure what is missing within the code but i cannot get it working for the life of me

<?php
/*
    * Let's make the proposed login name OBS friendly
    */
   $ahsayLoginName = $proposedAhsayLoginName;
   $ahsayLoginName = strtolower($ahsayLoginName);
   $code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
   $code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
   $ahsayLoginName = str_replace($code_entities_match, $code_entities_replace, $ahsayLoginName);

   /*
    * $ahsayProfile is an internal object that contains all data needed to create an account in OBS.
    * so here we basically populate an array that we will use to contruct the URI to actually make the API call
    */
$obsAccount = array (
      'username'   => "username", /* this is the username for the new account */
      'password'   => "password",  /* this is the password for the new account */
      'nickname'   => "Name Surname",
      'email'      => "email@someplace.com",
      'type'       => "OBM",
      'disksize'   => "1*1073741824", /* OBS wants size in bytes */
      'status'     => "enable",
      'clienttype' => "PAID", /* this is either PAID or TRIAL */
      'language'   => "EN",
      'timezone'   => "GMT+00:00 (BST)",
      'userhome'   => "\\san01-vlan101.phx1.hosteddatasolutions.net\123backup\Home Users Store",
      'bandwidth'  => "512*1024", 
      'mysqlAgent'    => "false",
      'mssqlAgent'    => "false",
      'oracleAgent'   => "false",
      'dominoAgent'   => "false",
      'notesAgent'    => "false",
      'exchangeAgent' => "false",
      'exchangeMailboxes' => "0",
      'infiledelta'   => "true",
      'shadowcopy'   => "true",
      ); 
   /*
    * Now we call the OBS API URI$ahsayProfile is an internal object that contains all data needed to create an account in OBS.
    * so here we basically populate an array that we will use to contruct the URI to actually make the API call
    */

 class obsConfig
 {
   function obsConfig()
   {

     $this->obsConfig['apiCall'] = 'AddUser.do';
  }
 }


     $command = "";

     if (!isset($obsAccount['username'])) {
        return array (
         'error' => 'No account name supplied!',
        );
     }

     if (!isset($obsAccount['type'])) {
        return array (
         'error' => 'No account type supplied!',
        );
     }

     $command .= '&LoginName='.urlencode($obsAccount['username']);

     if (isset($obsAccount['password'])) {
        $command .= '&Password='.urlencode($obsAccount['password']);
     }

     if (isset($obsAccount['nickname'])) {
        $command .= '&Alias='.urlencode($obsAccount['nickname']);
     }

     if (isset($obsAccount['email'])) {
        $command .= '&Email='.urlencode($obsAccount['email']);
     }

     if (isset($obsAccount['type'])) {
        $command .= '&Type='.urlencode($obsAccount['type']);
     }

     if (isset($obsAccount['disksize'])) {
        $command .= '&Quota='.urlencode($obsAccount['disksize']);
     }

     if (isset($obsAccount['status'])) {
        $command .= '&Status='.urlencode($obsAccount['status']);
     }

     if (isset($obsAccount['clienttype'])) {
        $command .= '&ClientType='.urlencode($obsAccount['clienttype']);
     }

     if (isset($obsAccount['language'])) {
        $command .= '&Language='.urlencode($obsAccount['language']);
     }

     if (isset($obsAccount['timezone'])) {
        $command .= '&Timezone='.urlencode($obsAccount['timezone']);
     }

     if (isset($obsAccount['bandwidth'])) {
        $command .= '&Bandwidth='.urlencode($obsAccount['bandwidth']);
     }

     if (isset($obsAccount['userhome'])) {
        $command .= '&UserHome='.urlencode($obsAccount['userhome']);
     }

     if (isset($obsAccount['enableAds'])) {
        if ($obsAccount['enableAds']) {
           $command .= '&EnableAds=Y';
        } else {
           $command .= '&EnableAds=N';
        }
     }

     if (isset($obsAccount['mysqlAgent'])) {
        if ($obsAccount['mysqlAgent']) {
           $command .= '&EnableMySQL=Y';
        } else {
           $command .= '&EnableMySQL=N';
        }
     }

     if (isset($obsAccount['mssqlAgent'])) {
        if ($obsAccount['mssqlAgent']) {
           $command .= '&EnableMSSQL=Y';
        } else {
           $command .= '&EnableMSSQL=N';
        }
     }

     if (isset($obsAccount['oracleAgent'])) {
        if ($obsAccount['oracleAgent']) {
           $command .= '&EnableOracle=Y';
        } else {
           $command .= '&EnableOracle=N';
        }
     }

     if (isset($obsAccount['dominoAgent'])) {
        if ($obsAccount['dominoAgent']) {
           $command .= '&EnableLotusDomino=Y';
        } else {
           $command .= '&EnableLotusDomino=N';
        }
     }

     if (isset($obsAccount['notesAgent'])) {
        if ($obsAccount['notesAgent']) {
           $command .= '&EnableLotusNotes=Y';
        } else {
           $command .= '&EnableLotusNotes=N';
        }
     }

     if (isset($obsAccount['exchangeAgent'])) {
        if ($obsAccount['exchangeAgent']) {
           $command .= '&EnableMSExchange=Y';
        } else {
           $command .= '&EnableMSExchange=N';
        }
     }

     if (isset($obsAccount['exchangeMailboxes'])) {
        if ($obsAccount['exchangeMailboxes'] > 0) {
           $command .= '&EnableExchangeMailbox=Y&ExchangeMailboxQuota='.$obsAccount['exchangeMailboxes'];
        } else {
           $command .= '&EnableExchangeMailbox=N&ExchangeMailboxQuota=0';
        }
     }

     if (isset($obsAccount['infiledelta'])) {
        if ($obsAccount['infiledelta']) {
           $command .= '&EnableInFileDelta=Y';
        } else {
           $command .= '&EnableInFileDelta=N';
        }
     }

     if (isset($obsAccount['shadowcopy'])) {
        if ($obsAccount['shadowcopy']) {
           $command .= '&EnableShadowCopy=Y';
        } else {
           $command .= '&EnableShadowCopy=N';
        }
     }

     // we add the credential infos
     $command .= '&SysPwd='.$sysPwd;
     $command .= '&SysUser='.$sysUser;

 class obs
 {
   function obsConfig()
   {

     $this->obsConfig['uri'] = 'http://backupserver.123-backup.com/obs/api/';
 {
   function obsConfig()
   {
     $result = $this->connect($this->obsConfig['uri'], $this->obsConfig['apiCall'], $command, 'POST');
   }
 }

     if (!$result) {
        return array (
           'error' => $this->error,
        );
     }

     if (strpos($result['dataXml'], 'OK') === false) {
          $x = new sfParseXmlMyRisk($result['dataXml']);
          $dataArray = $x->toArray();
          if(isset($dataArray['err'])) {
             return array (
            'error' => 'OBS API Account Creation Error: '. $dataArray['err'][0],
             );
          }
     } else {
          return null;
     }

/*code for the connect call */
  /**
   * Private method used to connect to our destination and retrieve results
   * If we return null, please check $this->error for information
   * Otherwise we return an array of elements
   *   dataXml  = raw results
   *   httpInfo = all Http call informations
   *
   * @param string url to call
   * @param string api command to call (if any)
   * @param string to deliver (if any)
   * @param string httpd method ('POST' or 'GET') (default POST)
   * @param boolean verify SSL certificate validity (default true)
   * @param boolean verify SSL certificate host (default true)
   * @param string user agent for HTTP request (default Mozilla 4.0)
   * @return null if error or array
   */
  function connect($url, $urlApi = null, $command = null, $method = 'POST', $verifyPeer=true, $verifyHost=true, $userAgent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')
  {

   if (empty($url)) {
      $this->error = 'Missing API url to call';
      return null;
   }

   $ch = curl_init();

   if (strtolower($method) == 'post') {
      curl_setopt($ch, CURLOPT_URL, $url . $urlApi);
      curl_setopt($ch, CURLOPT_POST,1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $command);
   } else {
      curl_setopt($ch, CURLOPT_POST,0);
      curl_setopt($ch, CURLOPT_URL, $url . $urlApi . $command);
   }
   curl_setopt($ch, CURLOPT_VERBOSE,1);
   curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifyPeer);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifyHost);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);


   $dataXml   = curl_exec($ch);
   $curlError = curl_error($ch);

   if($curlError) {
      $this->error = 'Curl Error: '.$curlError;
      return null;
   }

   $info = curl_getinfo($ch);

   if (empty($info['http_code'])) {
      $this->error = 'No HTTP code was returned';
      return null;
    }
   if (!(
      $info['http_code'] == '200' ||
      $info['http_code'] == '302'
   )) {
      $this->error = 'Http Code: '.$info['http_code'];
      return null;
   }

   return array (
      'dataXml'  => $dataXml,
      'httpInfo' => $info,
   );
  } 
?>

That error would imply you have a mismatched open/closing curly bracket somewhere in your code.

Is there any easy way to find this mismatch?

Is there any easy way to find this mismatch?

<?php
/*
    * Let's make the proposed login name OBS friendly
    */
   $ahsayLoginName = $proposedAhsayLoginName;
   $ahsayLoginName = strtolower($ahsayLoginName);
   $code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
   $code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
   $ahsayLoginName = str_replace($code_entities_match, $code_entities_replace, $ahsayLoginName);

   /*
    * $ahsayProfile is an internal object that contains all data needed to create an account in OBS.
    * so here we basically populate an array that we will use to contruct the URI to actually make the API call
    */
$obsAccount = array (
      'username'   => "username", /* this is the username for the new account */
      'password'   => "password",  /* this is the password for the new account */
      'nickname'   => "Name Surname",
      'email'      => "email@someplace.com",
      'type'       => "OBM",
      'disksize'   => "1*1073741824", /* OBS wants size in bytes */
      'status'     => "enable",
      'clienttype' => "PAID", /* this is either PAID or TRIAL */
      'language'   => "EN",
      'timezone'   => "GMT+00:00 (BST)",
      'userhome'   => "\\san01-vlan101.phx1.hosteddatasolutions.net\123backup\Home Users Store",
      'bandwidth'  => "512*1024", 
      'mysqlAgent'    => "false",
      'mssqlAgent'    => "false",
      'oracleAgent'   => "false",
      'dominoAgent'   => "false",
      'notesAgent'    => "false",
      'exchangeAgent' => "false",
      'exchangeMailboxes' => "0",
      'infiledelta'   => "true",
      'shadowcopy'   => "true",
      ); 
   /*
    * Now we call the OBS API URI$ahsayProfile is an internal object that contains all data needed to create an account in OBS.
    * so here we basically populate an array that we will use to contruct the URI to actually make the API call
    */

 class obsConfig
 {
   function obsConfig()
   {

     $this->obsConfig['apiCall'] = 'AddUser.do';
  }
 }


     $command = "";

     if (!isset($obsAccount['username'])) {
        return array (
         'error' => 'No account name supplied!',
        );
     }

     if (!isset($obsAccount['type'])) {
        return array (
         'error' => 'No account type supplied!',
        );
     }

     $command .= '&LoginName='.urlencode($obsAccount['username']);

     if (isset($obsAccount['password'])) {
        $command .= '&Password='.urlencode($obsAccount['password']);
     }

     if (isset($obsAccount['nickname'])) {
        $command .= '&Alias='.urlencode($obsAccount['nickname']);
     }

     if (isset($obsAccount['email'])) {
        $command .= '&Email='.urlencode($obsAccount['email']);
     }

     if (isset($obsAccount['type'])) {
        $command .= '&Type='.urlencode($obsAccount['type']);
     }

     if (isset($obsAccount['disksize'])) {
        $command .= '&Quota='.urlencode($obsAccount['disksize']);
     }

     if (isset($obsAccount['status'])) {
        $command .= '&Status='.urlencode($obsAccount['status']);
     }

     if (isset($obsAccount['clienttype'])) {
        $command .= '&ClientType='.urlencode($obsAccount['clienttype']);
     }

     if (isset($obsAccount['language'])) {
        $command .= '&Language='.urlencode($obsAccount['language']);
     }

     if (isset($obsAccount['timezone'])) {
        $command .= '&Timezone='.urlencode($obsAccount['timezone']);
     }

     if (isset($obsAccount['bandwidth'])) {
        $command .= '&Bandwidth='.urlencode($obsAccount['bandwidth']);
     }

     if (isset($obsAccount['userhome'])) {
        $command .= '&UserHome='.urlencode($obsAccount['userhome']);
     }

     if (isset($obsAccount['enableAds'])) {
        if ($obsAccount['enableAds']) {
           $command .= '&EnableAds=Y';
        } else {
           $command .= '&EnableAds=N';
        }
     }

     if (isset($obsAccount['mysqlAgent'])) {
        if ($obsAccount['mysqlAgent']) {
           $command .= '&EnableMySQL=Y';
        } else {
           $command .= '&EnableMySQL=N';
        }
     }

     if (isset($obsAccount['mssqlAgent'])) {
        if ($obsAccount['mssqlAgent']) {
           $command .= '&EnableMSSQL=Y';
        } else {
           $command .= '&EnableMSSQL=N';
        }
     }

     if (isset($obsAccount['oracleAgent'])) {
        if ($obsAccount['oracleAgent']) {
           $command .= '&EnableOracle=Y';
        } else {
           $command .= '&EnableOracle=N';
        }
     }

     if (isset($obsAccount['dominoAgent'])) {
        if ($obsAccount['dominoAgent']) {
           $command .= '&EnableLotusDomino=Y';
        } else {
           $command .= '&EnableLotusDomino=N';
        }
     }

     if (isset($obsAccount['notesAgent'])) {
        if ($obsAccount['notesAgent']) {
           $command .= '&EnableLotusNotes=Y';
        } else {
           $command .= '&EnableLotusNotes=N';
        }
     }

     if (isset($obsAccount['exchangeAgent'])) {
        if ($obsAccount['exchangeAgent']) {
           $command .= '&EnableMSExchange=Y';
        } else {
           $command .= '&EnableMSExchange=N';
        }
     }

     if (isset($obsAccount['exchangeMailboxes'])) {
        if ($obsAccount['exchangeMailboxes'] > 0) {
           $command .= '&EnableExchangeMailbox=Y&ExchangeMailboxQuota='.$obsAccount['exchangeMailboxes'];
        } else {
           $command .= '&EnableExchangeMailbox=N&ExchangeMailboxQuota=0';
        }
     }

     if (isset($obsAccount['infiledelta'])) {
        if ($obsAccount['infiledelta']) {
           $command .= '&EnableInFileDelta=Y';
        } else {
           $command .= '&EnableInFileDelta=N';
        }
     }

     if (isset($obsAccount['shadowcopy'])) {
        if ($obsAccount['shadowcopy']) {
           $command .= '&EnableShadowCopy=Y';
        } else {
           $command .= '&EnableShadowCopy=N';
        }
     }

     // we add the credential infos
     $command .= '&SysPwd='.$sysPwd;
     $command .= '&SysUser='.$sysUser;

 class obs
 {
   function obsConfig()
   {

     $this->obsConfig['uri'] = 'http://backupserver.123-backup.com/obs/api/';
 {
   function obsConfig()
   {
     $result = $this->connect($this->obsConfig['uri'], $this->obsConfig['apiCall'], $command, 'POST');
   }
 }

     if (!$result) {
        return array (
           'error' => $this->error,
        );
     }

     if (strpos($result['dataXml'], 'OK') === false) {
          $x = new sfParseXmlMyRisk($result['dataXml']);
          $dataArray = $x->toArray();
          if(isset($dataArray['err'])) {
             return array (
            'error' => 'OBS API Account Creation Error: '. $dataArray['err'][0],
             );
          }
     } else {
          return null;
     }

/*code for the connect call */
  /**
   * Private method used to connect to our destination and retrieve results
   * If we return null, please check $this->error for information
   * Otherwise we return an array of elements
   *   dataXml  = raw results
   *   httpInfo = all Http call informations
   *
   * @param string url to call
   * @param string api command to call (if any)
   * @param string to deliver (if any)
   * @param string httpd method ('POST' or 'GET') (default POST)
   * @param boolean verify SSL certificate validity (default true)
   * @param boolean verify SSL certificate host (default true)
   * @param string user agent for HTTP request (default Mozilla 4.0)
   * @return null if error or array
   */
   }
   
  function connect($url, $urlApi = null, $command = null, $method = 'POST', $verifyPeer=true, $verifyHost=true, $userAgent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')
  {

   if (empty($url)) {
      $this->error = 'Missing API url to call';
      return null;
   }

   $ch = curl_init();

   if (strtolower($method) == 'post') {
      curl_setopt($ch, CURLOPT_URL, $url . $urlApi);
      curl_setopt($ch, CURLOPT_POST,1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $command);
   } else {
      curl_setopt($ch, CURLOPT_POST,0);
      curl_setopt($ch, CURLOPT_URL, $url . $urlApi . $command);
   }
   curl_setopt($ch, CURLOPT_VERBOSE,1);
   curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifyPeer);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifyHost);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);


   $dataXml   = curl_exec($ch);
   $curlError = curl_error($ch);

   if($curlError) {
      $this->error = 'Curl Error: '.$curlError;
      return null;
   }

   $info = curl_getinfo($ch);

   if (empty($info['http_code'])) {
      $this->error = 'No HTTP code was returned';
      return null;
    }
   if (!(
      $info['http_code'] == '200' ||
      $info['http_code'] == '302'
   )) {
      $this->error = 'Http Code: '.$info['http_code'];
      return null;
   }

   return array (
      'dataXml'  => $dataXml,
      'httpInfo' => $info,
   );
}}
  
?>

thank you that is great many thanks for your help!

What kmonroe posted may eliminate your $end error, but all that code does is add a } after the closing bracket of your function, which is NOT where the actual error exists.

If you look at the original code you posted on line 203, you will see you have a function definition in class obs that has two opening curly brackets instead of an opening and closing curly bracket.

Oh dear, I was hoping the code was working ok. Look like I will have to pay some to sort this problem for me.

I'am not a php guru but I know a tiny bit.

If any one would like to help me get this problem fix please let me know.

Just fix the following code:

class obs
 {
   function obsConfig()
   {
 
     $this->obsConfig['uri'] = 'http://backupserver.123-backup.com/obs/api/';
 {
   function obsConfig()
   {
     $result = $this->connect($this->obsConfig['uri'], $this->obsConfig['apiCall'], $command, 'POST');
   }
 }

with

class obs
 {
   function obsConfig()
   {
 
     $this->obsConfig['uri'] = 'http://backupserver.123-backup.com/obs/api/';
 }
   function obsConfig()
   {
     $result = $this->connect($this->obsConfig['uri'], $this->obsConfig['apiCall'], $command, 'POST');
   }
 }

and don't add a } at the end of the file like was posted before.

I didn't even notice that when I posted before, not only was the bracket wrong, but the same function is declared twice in the class.

Without actually knowing how the code works there really isn't much anyone will be able to do to help you resolve the issue. You need to eliminate one of those functions, or combine them, but they seem to be doing two different things.

Oh dear, I was hoping the code was working ok. Look like I will have to pay some to sort this problem for me.

I'am not a php guru but I know a tiny bit.

If any one would like to help me get this problem fix please let me know.

Sorry Bout that...I am also not a php guru... nor did I catch the other errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.