coldfusion cfhttp to PHP
Asked Answered
C

2

6

I've designed a website Im running for a sports team I coach in Wordpress (more specifically PHP). For the past few years we have used an online web service that runs a stats based program in Coldfusion. They recently opened up a feed so users can use there own customized websites with their data implemented in it.

They provided me with a feed like so (not going to provide my details for security reasons):

<cfhttp url="http://datafeed" method="post" result="result">
            <cfhttpparam type="formfield" name="seasonID" value="29725">
            <cfhttpparam type="formfield" name="codekey" value="mycodekey">
<cfhttpparam type="formfield" name="showGameType" value="RS">
</cfhttp>

I have no experience with Coldfusion what so ever and I've tried to do some reading about using this in a PHP environment but everything I tend to find is PHP to Coldfusion, not the opposite.

Because of this I come to stack, Im not entirely sure how this would work within PHP but would cURL be the answer? Ideally Id like to just create a couple wordpress functions and call them on my template pages.

Chrotoem answered 1/8, 2012 at 19:41 Comment(3)
Great question! What, precisely, is the functionality you're trying to implement?Farfamed
The code above does an HTTP call (same as curl or wget) using POST and passing in params. datafeed - could be blah.com/something.php - and Viala! you are accessing PHP from coldfusion :)Bernhard
Matt, essentially they have prodvided me with a list of feeds that give access to stats, rosters, schedules etc. From my understanding all that should happen is displaying of said tables on my website. I want to continue to be able to read stats from league database site (ColdFusion) and display them on my Wordpress Site.Chrotoem
B
4

The code example you have there is a simple form style http post with the response from the post being written to the variable "result".

The form post contains three fields; "seasonid", "codekey" and "showgametype".

To be honest I have no clue how you would write it in PHP, cURL is the library you will need to use. The examples in the comments on the main cURL page look to do what you would need; capture the http response from a post or get to a URL.

Hopefully my description of what the example code is doing will help you determine your course.

Burgomaster answered 1/8, 2012 at 20:16 Comment(3)
Thanks Stephen, as Im very unfamiliar with ColdFusion if I were to display the results of the mentioned above I would do so with #result.FileContent# correct? That would display the aforementioned form values? I understand what the code is doing I suppose the next step is taking what they've provided and implementing it into PHP.Chrotoem
Quickly add to this, would it be possible to store the data from the above code into a JSON string and access it that way?Chrotoem
Yes the response would contain a structure key called file content if you use cfhttp. I am not sure what the cURL equivalent would be. If you are actually calling a page with a cfc file extension then yes you can use a form or URL variable called "returnformat" to request the response as json as opposed to xml or wddx. (set returnformat to json in the submission). However if you are calling a cfm page then you are restricted to what ever format the third party returns and you would have to parse it with PHP functions to get the data format you want.Burgomaster
C
0

Thanks all for the help managed to figure this out with some hints provided above.

The datafeed where I was accessing the information needed the codekey obviously which I wasnt sure how to figure out but managed to get it, this is what I used, not 100% sure if its right but Ive managed to retrieve the data which ended up being in JSON format.

If there are any tips to this solution Im all ears..

function name() {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://urlhere.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, false);

$data = array(
    'codekey' => 'mycodekey'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$rawdata = curl_exec($ch);
curl_close($ch);

//Convert Returned JSON data to PHP Object
$output = (json_decode($rawdata));


foreach($output->DATA as $key => $val) {
    echo "<br />" . $val[1];
}

This was a little different then my example above as I decided to use an easier feed that just had the seasons because the JSON data returned in my feed above had a lot more data (GP, Wins, Losses, Ties, PTS,) etc.

Chrotoem answered 3/8, 2012 at 5:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.