Forum Moderators: coopster

Message Too Old, No Replies

APIs in PHP

Errors

         

ph0t0bug

2:44 pm on May 21, 2007 (gmt 0)

10+ Year Member



I have a friend who is having problems with some APIs in PHP... the following is the error he is getting:

Parse error: parse error, unexpected $ in /home/content/l/a/b/laban/html/php/simlib.php on line 54

I have to admit I know nothing about server side scripting but I told him I would take it to the pros :)

If you need more info I can post it I just did not want to fill the message with drivel that was not needed.

jatar_k

2:57 pm on May 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ph0t0bug,

what is on line 54? could you post them, and maybe a line or two before as well.

ph0t0bug

3:03 pm on May 21, 2007 (gmt 0)

10+ Year Member



Ok.. here is the whole thing:

First e-mail that I got from him:
------------------------------
need a VERY SIMPLE solution to integrating a website “order” to Authorize.net’s gateway. This is so simple it really shouldn’t be kicking my butt so bad, but it is. All I need to do is set up a client’s site with a button that’ll send them to a payment form (already set up) on Authorize.net’s system. I tried following all their directions, even used one of their templates. Still getting errors.
-------------------------------

Then I he gave me this info:

--------------------------------
Well….here is the beastie:

<?

// DISCLAIMER:

// This code is distributed in the hope that it will be useful, but without any warranty;

// without even the implied warranty of merchantability or fitness for a particular purpose.

// Main Interfaces:

//

// function InsertFP ($loginid, $x_tran_key, $amount, $sequence) - Insert HTML form elements required for SIM

// function CalculateFP ($loginid, $x_tran_key, $amount, $sequence, $tstamp) - Returns Fingerprint.

// compute HMAC-MD5

// Uses PHP mhash extension. Pl sure to enable the extension

function hmac ($key, $data)

{

// RFC 2104 HMAC implementation for php.

// Creates an md5 HMAC.

// Eliminates the need to install mhash to compute a HMAC

// Hacked by Lance Rushing

$b = 64; // byte length for md5

if (strlen($key) > $b) {

$key = pack("H*",md5($key));

}

$key = str_pad($key, $b, chr(0x00));

$ipad = str_pad('', $b, chr(0x36));

$opad = str_pad('', $b, chr(0x5c));

$k_ipad = $key ^ $ipad ;

$k_opad = $key ^ $opad;

return md5($k_opad . pack("H*",md5($k_ipad . $data)));

// Calculate and return fingerprint

// Use when you need control on the HTML output

function CalculateFP ($loginid, $x_tran_key, $amount, $sequence, $tstamp, $currency = "")

{

return (hmac ($x_tran_key, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency));

}

function InsertFP ($loginid, $x_tran_key, $amount, $sequence, $currency = "")

{

$tstamp = time ();

$fingerprint = hmac ($x_tran_key, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency);

echo ('<input type="hidden" name="x_fp_sequence" value="' . $sequence . '">' );

echo ('<input type="hidden" name="x_fp_timestamp" value="' . $tstamp . '">' );

echo ('<input type="hidden" name="x_fp_hash" value="' . $fingerprint . '">' );

return (0);

?>

I have a PHP file that collects data and then calls on this file to create the fingerprint needed to communicate securely with Authorize.net….then supposedly the Authorize.net secure payment form should call up and accept input from the user for a CC transaction…then after that the authorize.net stuff handles the transaction and returns an email and customized page/receipt.

So my form is doing what it is supposed to do….by calling this file. But this file keeps giving me errors. Here’s the latest:

Parse error: parse error, unexpected $ in /home/content/l/a/b/laban/html/php/simlib.php on line 54
-----------------------

I hope this helps
-Wilson

jecasc

3:44 pm on May 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Usually when a function ends you close it with a }.

Tell him to close his functions with } after the "return" statements in line 51 and line 79.

He should consider using an editor with build in error correction like the free "EasyEclipse". Should save him a lot of time. After I pasted the script in my editor it immediately showed where the error was.

ph0t0bug

4:25 pm on May 21, 2007 (gmt 0)

10+ Year Member



Thanks so much for your help. I have forwared the info to him and will let you know how it turns out.

-Wilson