我有一个php脚本,可以在本地IIS / PHP环境和BlueHost CentOS linux服务器上正常运行。但是在另一台linux服务器上,出现以下错误:
解析错误:语法错误,意外出现$ end [路径...]
这是该服务器上的phpinfo()
:
在无法正常工作的服务器上,我尝试了标准php标签<?php ?>
和短标签<? ?>
-没什么区别。
最初在有问题的linux服务器上,我什至无法使phpinfo()
正常工作,但是随后我在NPP中将编码转换为ANSI并将脚本上载到服务器后,phpinfo()正常工作。我在真正的php脚本上尝试了完全相同的操作,然后继续出现上述错误。
我已经读过很多关于此错误的SO和其他文章,他们都说我缺少结尾的花括号或类似的花括号,但是如果是这样的话,它也会在我的本地计算机上损坏-但是它没有。
我可以发布我的PHP源代码,但是考虑到它可以在1个IIS / PHP和1个Linux CentOS上完美执行,我真的认为它与代码没有任何关系。必须有一些环境差异,但我不知道是什么。
代码如下:
<?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;
}
?>
我完全陷入了困境。有什么想法吗?