-1

I am working on something which unfortunately does not have anything in CF, so there are few things which i am trying to do to convert but some functions which i am not sure what is the equivalent of those in Coldfusion, any guidance will be helpful

$nonce = explode(' ', microtime());
$request['nonce'] = $nonce[1] . str_pad(substr($nonce[0], 2, 6), 6, '0');

for the above, to me it seems just a timestamp in ACF , if i am doing wrong please guide, because i am not sure what explode and str_pad is doing here

so my CF equivalent is:

<cfset nonce = createobject("java","java.lang.System").currentTimeMillis() & "000">

what is base64_decode and base64_encode of PHP in ACF

i think binaryencode and binmarydecode but i am not sure

and i tried finding a lot what is http_build_query in PHP as to Coldfusion, but i think its cfhttp but i have no clue

Jhing
  • 41
  • 4
  • My recommended method for rewriting something in another programming language is to first write it out in whatever language you speak, English, French, whatever. Then use that document as a specification. – Dan Bracuk Jan 18 '21 at 13:44

2 Answers2

2

I'd suggest you bookmark the main Adobe ColdFusion documentation, as well as the community docs:

If you just Google "base64 encode with ColdFusion", you'll find the related functions.

https://cfdocs.org/tobase64

toBase64(string_or_object [, encoding]) → returns string

https://cfdocs.org/tobinary

toBinary(base64_or_object) → returns binary

You won't find a lot of resources about directly converting from CF to PHP or vice-versa. But if you look up what the actual PHP function DOES, then you're more likely to find the related CF function.

https://www.php.net/manual/en/function.http-build-query.php

http_build_query ( mixed $query_data , string $numeric_prefix = ? , string $arg_separator = ? , int $enc_type = PHP_QUERY_RFC1738 ) : string

Generates a URL-encoded query string from the associative (or indexed) array provided.

This takes the result of a query in PHP and converts it to the query string for a URL.

column1=A&column2=B

I don't think there's a CF function that does exactly that, but you can loop over the columns in the result of a cfquery and create the same output string using the CF function encodeForURL() on the query string parameter values.

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • Thanks, i know there are some hicups while finding the equivalents in ACF, Another catch is i think my nounce is correct because it seems you did not mentioned it, because i had no clue what the str_pad be in Coldfusion, as per PHP, it seems it is adding padding to the string on the one of the side, left or right – Jhing Jan 18 '21 at 12:28
0

There's a third-party function to do that:

/**
 * Converts a structure to a URL query string.
 * 
 * @param struct      Structure of key/value pairs you want converted to URL parameters 
 * @param keyValueDelim      Delimiter for the keys/values.  Default is the equal sign (=). 
 * @param queryStrDelim      Delimiter separating url parameters.  Default is the ampersand (&). 
 * @return Returns a string. 
 * @author Erki Esken (erki@dreamdrummer.com) 
 * @version 1, December 17, 2001 
 */
function StructToQueryString(struct) {
  var qstr = "";
  var delim1 = "=";
  var delim2 = "&";

  switch (ArrayLen(Arguments)) {
    case "3":
      delim2 = Arguments[3];
    case "2":
      delim1 = Arguments[2];
  }
    
  for (key in struct) {
    qstr = ListAppend(qstr, URLEncodedFormat(LCase(key)) & delim1 & URLEncodedFormat(struct[key]), delim2);
  }
  return qstr;
}

Source: https://cflib.org/udf/StructToQueryString

Harry
  • 11
  • 1
  • A little warning, this function lower-cases each query parameter name. You can disable that by removing "LCase()". – Harry Aug 16 '22 at 12:21