I have a php script that runs fine on my local IIS/PHP environment and on a BlueHost CentOS linux server. But on another linux server, I get the following error:
Parse error: syntax error, unexpected $end in [path...]
Here is the phpinfo()
from that server:
On the server that doesn't work, I have tried both standard php tags <?php ?>
and short tags <? ?>
- makes no difference.
Originally on the problematic linux server I couldn't even get phpinfo()
to work, but then after I converted the encoding to ANSI in NPP and uploaded the script to the server, the phpinfo() worked. I tried the same exact thing on my real php script and I continue to get the error above.
I have read numerous SO and other posts about this error, and they all say that I'm missing an ending curly brace or similar, but if that were the case, it would break on my local machine as well - but it doesn't.
I could post my PHP source code but I really don't think it has anything to do with the code, given the fact that it executes perfectly on 1 IIS/PHP and 1 linux CentOS. There must be some environmental difference but I can't figure out what it is.
Here is the code:
<?php
require_once "functions.php";
$isTest = false;
$isLocalhost = ($_SERVER["HTTP_HOST"] == "localhost" || $_SERVER["HTTP_HOST"] == "frisbee2");
if($_GET["Secret"] != "****************"){
die("Incorrect secret.");
}
if($isTest){ // TEST/SANDBOX
$apiLoginID = "********"; // sandbox
$transactionKey = "********"; // sandbox
$url = "https://apitest.authorize.net/xml/v1/request.api"; // sandbox
}else{ // LIVE/PROD
$apiLoginID = "********"; // LIVE
$transactionKey = "********"; // LIVE
$url = "https://api2.authorize.net/xml/v1/request.api"; // LIVE
}
$xmlRequest="
<ARBGetSubscriptionListRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">
<merchantAuthentication>
<name>$apiLoginID</name>
<transactionKey>$transactionKey</transactionKey>
</merchantAuthentication>
<searchType>subscriptionActive</searchType>
<sorting>
<orderBy>id</orderBy>
<orderDescending>false</orderDescending>
</sorting>
<paging>
<limit>1000</limit>
<offset>1</offset>
</paging>
</ARBGetSubscriptionListRequest>";
if($xmlRequest){
$response = SendToAuthorizeNet($url, $xmlRequest);
$jsonObject = json_decode($response);
$recordCount = $jsonObject->totalNumInResultSet;
$subscriptions = $jsonObject->subscriptionDetails->subscriptionDetail;
writeme("Total subscriptions: $recordCount");
writeme("========================================");
foreach ($subscriptions as $key => $value){
$subscriptionID = $value->id;
$amount = $value->amount;
$firstName = $value->firstName;
$lastName = $value->lastName;
if($amount == 40){
$newAmount = 43;
}else if($amount == 30){
$newAmount = 36;
}else{
$newAmount = $amount; // this will happen only AFTER a subscription amount has been updated to the new price
}
writeme("Customer: $firstName $lastName");
writeme("current amount: $$amount");
writeme("<b>new amount: $" . number_format($newAmount, 2) . "</b>");
writeme("subscriptionID: $subscriptionID");
if($newAmount > $amount){
/* comment back in block below to run in LIVE
$success = UpdateARB($subscriptionID, $newAmount);
if($success){
writeme("<font color='blue'><b>Success!</b></font>");
}else{
writeme("<font color='red'><b>FAIL</b></font>");
}
*/
}
writeme("========================================");
}
writeme("*** Processing complete. ***");
}
function UpdateARB($subscriptionID, $newAmount){
global $apiLoginID, $transactionKey, $url;
$xmlRequest="
<ARBUpdateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">
<merchantAuthentication>
<name>$apiLoginID</name>
<transactionKey>$transactionKey</transactionKey>
</merchantAuthentication>
<subscriptionId>$subscriptionID</subscriptionId>
<subscription>
<amount>$newAmount</amount>
</subscription>
</ARBUpdateSubscriptionRequest>";
$response = SendToAuthorizeNet($url, $xmlRequest);
$jsonObject = json_decode($response);
return ($jsonObject->messages->resultCode == "Ok" && $jsonObject->messages->message->text == "Successful.");
//echo "<pre>";
//print_r($jsonObject);
//echo "<pre>";
}
function parse_api_response($content)
{
$parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING);
if ($parsedresponse->messages->resultCode != "Ok") {
//writeme("got here");
echo "The operation failed with the following errors:<br>";
foreach ($parsedresponse->messages->message as $msg) {
writeme("[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text));
}
writeme("");
}
return $parsedresponse;
}
function MerchantAuthenticationBlock() {
global $apiLoginID, $transactionKey;
return
"<merchantAuthentication>".
"<name>" . $apiLoginID . "</name>".
"<transactionKey>" . $transactionKey . "</transactionKey>".
"</merchantAuthentication>";
}
//function to send xml request to Api.
//There is more than one way to send https requests in PHP.
function send_xml_request($content)
{
global $authNetApiHost, $authNetAPIPath;
return send_request_via_fsockopen($authNetApiHost,$authNetAPIPath,$content);
}
function SendToAuthorizeNet($url, $request){
$ch = curl_init();
if (FALSE === $ch){
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
curl_close($ch);
$xmlResult = simplexml_load_string($content);
$jsonResult = json_encode($xmlResult);
return $jsonResult;
}
?>
I am completely stumped. Any ideas?