Coldfusion cfhttp for PHP

I developed the Im website working in a sports team that I train in Wordpress (more precisely, PHP). Over the past few years, we have used an online service that launches statistics-based software in Coldfusion. They recently opened a feed so that users can use their own websites with their data embedded in it.

They provided me with such a feed (I will not provide my data 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 that I have ever done, and I tried to do some reading about using this in a PHP environment, but all I usually found was PHP for Coldfusion, not the other way around.

Because of this, I came on the stack, I'm not quite sure how this will work in PHP, but will cURL be the answer? Ideally Id like to just create some Wordpress features and call them on my template pages.

+6
source share
2 answers

The sample code that you have is a simple HTTP message in which the response from the record is written to the "result" variable.

The form message contains three fields; seasonal, code key, and showgametype.

Honestly, I have no idea how you write it in PHP, cURL is the library you will need to use. The examples in the comments on the cURL main page are for what you need; capture HTTP response from message or get url.

Hopefully my description of what the sample code does will help you determine your course.

+4
source

Thanks to everyone for their help, I managed to figure this out with some of the tips given above.

The data in which I accessed the information needed a code code, obviously I was not sure how to find out, but I managed to get it, this is what I used, and not 100% sure that if it were right but Ive managed to get the data which turned out to be in JSON format.

If there are any clues 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]; } 

It was a little different than in my example above, since I decided to use a lighter channel that just had seasons because the JSON data returned in my channel above had a lot more data (GP, Wins, Losses, Ties, PTS, ) etc.

0
source

Source: https://habr.com/ru/post/921882/


All Articles