Skip to main content
September 11, 2008
Question

Help translating a few line of PHP to CF

  • September 11, 2008
  • 7 replies
  • 452 views
This is for an API for a project im working on.
Would someone be so kind as to help me translate this over from PHP.
I need it in Cold Fusion, and eventually Perl and Python...

For those not familiar with PHP:
- The "." (period) in the $md5 line just concats the $query and $secret strings
- $var is a variable, and when placed in double quotes $var will be replaced with its value,
eg. $var="world"; echo "Hello $var"
Thanks!!
This topic has been closed for replies.

7 replies

BKBK
Community Expert
Community Expert
September 13, 2008
September 11, 2008
CORRECTION -- in my last code, the url was NOT https, like it should have been.

so would this code need to be changed to https?


<cfhttp url="#url#">
<cfset response = cfhttp.filecontent>


September 11, 2008
btw... after you post, please email me with your paypal address to
$atsign="@"
"tim" + "h" +$atsign + "vy " + "ew.com"
September 11, 2008
Ian... thanks for the response.

>Why would one send a plain text string and that
same string md5 hashed

The idea is that its being sent over HTTPS anyways, so it is encrypted. The purpose of the plaintext + hash, is just to authenticate that call.

On the backend, we just take the hash, and see if it matches the plaintext + secret that we store in the db.

Hey I got another question.
I have updated the PHP code into a function that i need translated.
Its a little different now.
Can you port that for me, and i'll send you $10 over paypal?

thanks!
Inspiring
September 11, 2008
P.S.

Just out of curiosity. Why would one send a plain text string and that
same string md5 hashed to some API?

Inspiring
September 11, 2008
CORRECTIONS:
* Corrected 'mdf' typo to 'md5'
* Concatenated the 'secret' string to the 'query' string in the md5
hash function.

<cfscript>
apikey = "MY_API_KEY";
secret = "MY_SECRET";
apiurl = " http://domain.com/api";
epoch_time = now();

query = "cmd=MY_COMMAND&key=#apikey#&time=#epoch_time";
md5 = hash(query & secret,"MD5");
url = "#apiurl#?#query#&md5=#md5#;
</cfscript>

<cfhttp url="#url#">
<cfset response = cfhttp.filecontent>
Inspiring
September 11, 2008
Untested and only typed once into this reply.

<cfscript>
apikey = "MY_API_KEY";
secret = "MY_SECRET";
apiurl = " http://domain.com/api";
epoch_time = now();

query = "cmd=MY_COMMAND&key=#apikey#&time=#epoch_time";
mdf = hash(query,"MD5");
url = "#apiurl#?#query#&md5=#md5#;
</cfscript>

<cfhttp url="#url#">
<cfset response = cfhttp.filecontent>