curl response content not complete - php

I am working with api ( using curl and php ) that is supposed to return a batch of csv records based on a date. First, you make a request that returns the number of records that will be in the batch. The second request is to actually retrieve the records. My problem is when I make the second request I do NOT get the number of records that the first request indicates I am to get. Regardless of the date selected I ALWAYS get 7167 records ( the number of records for any particular day will be over 8000 ). The content length I received is what the header states I am to get. I do not get any errors. Here is the rub, if I put the url request in a browser's address bar I get ALL the records I am supposed to get.
The script runs on a linux platform. In fact, I have tried it on another linux server with the same results. I have tried changing execution time and timeout setting. I am really baffled. Thank you in advance for your suggestions.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0); // no limit
$username = "*********";
$pwd = "*********";
$urlCount = "https://*********&fromDate=". $today . "&toDate=" . $tomorrow";
$TotalPages = 0;
$CurrentPage = 0;
$PageSize = 1;
$RecordCount = 0;
$TotalRecordsProcessed = 0;
$today = date( "Y-m-d" );
$tomorrow = date( 'Y-m-d', strtotime( "+1 days" ) );
echo "today " . $today . "<br>";
echo "tomorrow: " . $tomorrow . "<br>";
$urlCount = "https://*********&fromDate=". $today . "&toDate=" . $tomorrow;
$headers = array("Content-Type:text/plain", 'Connection: Keep-Alive');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlCount );// Get the count of the records we asked for
curl_setopt($ch, CURLOPT_HEADER, true );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true );
curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt($ch, CURLOPT_VERBOSE, true );
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $pwd );
$result = curl_exec( $ch ); // execute the curl function
$lines = explode( "\r\n", $result );
$idx = 0;
while( $lines[ $idx ] != null ) $idx++; // find the empty line
$RecordCount = $lines[ $idx + 1 ]; // This is the index to the number of records in the set
$PageSize = $RecordCount;
echo "Records in set: " . $RecordCount . "<br>";
$url = "https://***********&fromDate=2015-10-19&toDate=2015-10-20&pageSize=" . $PageSize . "&pageNumber=" . $CurrentPage . "&timezone=Eastern&outputType=csv";
curl_setopt($ch, CURLOPT_URL, $url ); // set the url for getting the records
$result = curl_exec( $ch ); // execute the function
$info = curl_getinfo($ch);
curl_close( $ch );
$size_download = $info["size_download"];
echo "Http Code: " . $info['http_code'] . "<br>";
echo "Size download: " . $info["size_download"] . "<br>";
// Make sure the length of the content received is the same as the "size_download" from the http header
$pos = strpos( $result, "UUID" ) - 2; // find the begining of the content
$result = substr( $result , $pos, -1 ); // remove the header data...keep just the content
$len = strlen( $result ); // get the length of the received content
if( $len != $size_download )
{
echo "length:" . strlen( $result ) . "<br>";
echo "Content recieved not = size_download<br>";
}
// Check to make sure records downloaded match the number of records that the first curl request says there are
// Records are in csv format
$lines = explode( "\r\n", $result );
$RecordsReceived = count( $lines );
if( $RecordsReceived != $RecordCount )
{
echo "Record Count = " . $RecordCount . " RecordsReceived = " . $RecordsReceived . "<br>";
}
?>

Related

Change proxy service on php file

I have this code that I need to edit by replacing PhantomJsCloud services with brightdata service
function ms_getUrl($url){
$json = urlencode('{url:"' . $url . '",renderType:"plainText",outputAsJson:true}');
$res = getUrl('https://PhantomJsCloud.com/api/browser/v2/ak-4sr84-tyab5-0iyd6-d9w6h-6pw35/?request=' . $json);
$res = json_decode('[' . $res . ']' , 1);
$res = $res[0]['pageResponses'][0]['frameData']['content'];
return $res;
echo '<pre>' . print_r( json_decode('[' . $res . ']' , 1) , 1 ) . '</pre>';exit;
}
This is brightdata example provided by them
<?php
echo 'To enable your free eval account and get CUSTOMER, YOURZONE and '
.'YOURPASS, please contact sales#brightdata.com';
$curl = curl_init('http://lumtest.com/myip.json');
curl_setopt($curl, CURLOPT_PROXY, 'http://zproxy.lum-superproxy.io:22225');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'brd-customer-hl_2bevke7f-zone-static:0vavfolixyu6q');
curl_exec($curl);
?>
I tried this but it doesn't use brightdata proxies
function ms_getUrl($url){
$json = urlencode('{url:"' . $url . '",renderType:"plainText",outputAsJson:true"}');
$res = getUrl('http://brd-customer-hl_2bjki87f-zone-static:0vavfkjkyu6a#zproxy.lum-superproxy.io:22225' . $json);
$res = json_decode('[' . $res . ']' , 1);
$res = $res[0]['pageResponses'][0]['frameData']['content'];
return $res;
echo '<pre>' . print_r( json_decode('[' . $res . ']' , 1) , 1 ) . '</pre>';exit;
}

Simple HTML Dom change link source dinamically

I have a page where I extract "a href" link with a specific "td class". This is my code and my output:
extractlink.php
<?php
include('../simple_html_dom.php');
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
return #curl_exec($ch);
}
$linkurl = "http://www.betexplorer.com/soccer/czech-republic/1-liga/results/";
$response=getHTML($linkurl);
$html = str_get_html($response);
foreach($html->find("td[class=h-text-center]/a") as $div) {
$show = 'http://www.betexplorer.com' .$div->href . '<br>';
echo $show;
}
?>
extractlink.php output:
Now I'd like to put each link dynamically in my getHTML url into my single.php page. Below you can see code and output:
<?php
include('../simple_html_dom.php');
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
return #curl_exec($ch);
}
$response=getHTML("http://www.betexplorer.com/soccer/czech-republic/1-liga/brno-slovacko/Sxc6EbMS/",10);
$html = str_get_html($response);
$titles = $html->find("span[class=list-breadcrumb__item__in]"); // 1 per match
$result = $html->find("p[id=js-score]"); // 1
$partial = $html->find("h2[id=js-partial]"); // 1
$best_bets = $html->find("td[class=table-matches__odds colored]/span/span/span"); // 1
$odds = $html->find("td[class=table-matches__odds]"); // 2
function print_odd($odd) {
if (array_key_exists('data-odd', $odd->attr)) {
return $odd->attr['data-odd'];
}
return $odd->children(0)->children(0)->children(0)->attr['data-odd'];
}
$c=0; $b=0; $o=0; $z=0; $h=0; $d=0; $s=0;// two counters
foreach ($titles as $match) {
list($num1, $num2) = explode(':', $result[$c++]->innertext); // <- explode
$num1 = intval($num1);
$num2 = intval($num2);
$num3 = ($num1 + $num2);
$risultato = ($num1 . '-' . $num2);
$risultatounito = ($num1 . '-' . $num2);
list($home, $away) = explode('-', $titles[$z++]->innertext); // <- explode
list($partialht, $partialft) = explode(',', $partial[$o++]->innertext); // <- explode
$partialht = str_replace('(', '', $partialht);
$partialft = str_replace(')', '', $partialft);
$rest = substr($partialht, -1);
$firstCharacter = $partialht[0];
$lastCharacter = $partialht[2];
$firstCharacters = $partialft[1];
$lastCharacters = $partialft[3];
$firstCharacter = intval($firstCharacter);
$lastCharacter = intval($lastCharacter);
$firstCharacters = intval($firstCharacters);
$lastCharacters = intval($lastCharacters);
$somma = $firstCharacter + $lastCharacter;
$sommatwo = $firstCharacters + $lastCharacters;
list($homescoreht, $awayscoreht) = explode(':', $partialht[$d++]->innertext); // <- explode
$homescoreht = intval($homescoreht);
$awayscoreht = intval($awayscoreht);
list($homescoreft, $awayscoreft) = explode(':', $partialft[$s++]->innertext); // <- explode
$homescoreft = intval($homescoreft);
$awayscoreft = intval($awayscoreft);
if ($somma > 0){
$over05ht = "Over 0.5 HT";
}else{
$over05ht = "Under 0.5 HT";
}
if ($num3 > $somma){
$over05sh = "Over 0.5 SH";
}else{
$over05sh = "Under 0.5 SH";
}
$odd1 = print_odd($odds[$b++]);
$odd2 = print_odd($odds[$b++]);
$odd3 = print_odd($odds[$b++]);
$home = strip_tags($home);
$away = strip_tags($away);
$uniquefield = $home . ' ' . $away;
echo "<tr><td class='rtitle'>".
"<td> ".$home.'</td><td> : </td><td>'.$away . " / " . // <- example use
"<td> ".$num1.'</td><td> : </td><td>'.$num2 . " / " . // <- example use
"<td class='first-cell'>".$partialht ."</td> " .
"<td class='first-cell'>".$partialft ."</td> " .
"<td class='first-cell'>".$firstCharacter ."</td> " .
"<td class='first-cell'>".$lastCharacter ."/</td> " .
"<td class='first-cell'>".$firstCharacters ."</td> " .
"<td class='first-cell'>".$lastCharacters ."/</td> " .
"<td class='first-cell'>".$somma ."/</td> " .
"<td class='first-cell'>".$num3 ."/</td> " .
"<td class='first-cell'>".$over05ht ."/</td> " .
"<td class='first-cell'>".$over05sh ."/</td> " .
"<td class='odds'>".$odd1 . ";" .
"".$odd2 . ";" .
"".$odd3 . "</td>" .
"<td class='first-cell'>".$uniquefield ."</td> " .
"</td></tr><br/>";
} //close foreach
?>
single.php output:
So, I'd like to change getHTML url into single.php and inserting each url from extractlink.php

PHP getting JSON data not working

Does anyone know how I can get the data from the JSON data
{
"data":{
"verify-purchase":{
"item_name":"Simplified PHP Invoice \/ Billing System",
"item_id":"11438884",
"created_at":"Sun May 31 07:49:31 +1000 2015",
"buyer":"aurysilva",
"licence":"Regular License"
}
},
"code":200,
"msg":"SUCCESS. Simplified PHP Invoice \/ Billing System License Activated. Purchase date: Sun May 31 07:49:31 +1000 2015"
}
If I do:
<?php
$LE = new License_Enforcer( 'http://www.rebootdigital.co.uk/verify.php');
$username = LICENSE_USERNAME;
$purchase_code = LICENSE_KEY;
$verified = $LE->verify($username, $purchase_code);
// save the result
$license_verified = $verified;
//$class = $LE->return_code >= 200 ? 'update' : 'error';
//echo sprintf("<div id='message' class='%s'><p>%s</p></div>", $class, $LE->msg);
echo $LE->msg;
echo $LE->data->item_name;
?>
$LE->msg returns the msg data, but I am not sure how to get the actual data.
JSON code:
// Make curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OD X; en-us) AppleWebKit/535.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5");
$url = 'http://marketplace.envato.com/api/edge/'.$envato_author_username.'/'.$envato_author_apikey.'/verify-purchase:'.$envato_purchase_code.'.json';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch_data = curl_exec($ch);
curl_close($ch);
if ( empty( $ch_data ) ) { # no data returned - Timeout or similar
$result['code'] = 111;
$result['msg'] = 'FAILED to Activate License. Envato API request returned: ' . curl_error( $ch ) . " Please try again later.";
}
else {
$json_data = json_decode( $ch_data, true );
$result['data'] = $json_data;
if ( isset( $json_data['verify-purchase'] ) && count( $json_data['verify-purchase']) > 0 ) {
$license_type = $json_data['verify-purchase']['licence'];
$item_name = $json_data['verify-purchase']['item_name'];
$item_id = $json_data['verify-purchase']['item_id'];
$buyer = $json_data['verify-purchase']['buyer'];
$created_at = $json_data['verify-purchase']['created_at'];
if ( strcasecmp( $envato_username, $buyer ) === 0 ) {
$result['code'] = 200;
$result['msg'] = "SUCCESS. " . $item_name . " License Activated. Purchase date: " . $created_at;
}
else {
$result['code'] = 122;
$result['msg'] = "FAILED to Activate License for " . $item_name . ". Envato states this purchase code is owned by another user.";
}
} else if ( $json_data['error'] ) {
$result['code'] = 112;
$result['msg'] = 'FAILED to Activate License. Envato API request returned: ' . $json_data['error'];
} else {
$result['code'] = 121;
$result['msg'] = 'FAILED to Activate License. Envato states purchase code ' . $envato_purchase_code . ' is not valid.';
}
$result = str_replace('verify-purchase','verify_purchase',$data);
}
}
echo json_encode( $result );
echo "\n";
// update log file
$logfile = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.log';
$fh = #fopen( $logfile ,"a" );
if ($fh) {
fwrite( $fh, date( 'Y-m-d H:i:s',time() ) . ' ');
fwrite( $fh, $envato_username . ' ' );
fwrite( $fh, $envato_purchase_code . ' ' );
fwrite( $fh, $website . ' ');
fwrite( $fh, isset( $item_name ) ? '"' . $item_name . '"' : '-' );
fwrite( $fh, ' ==> ' );
fwrite( $fh, $result['code'] . ' ' );
fwrite( $fh, '"' . $result['msg'] . '" ');
fwrite( $fh, "\n" );
fclose($fh);
}
?>
anant's anwer is missing quotes around the property name 'verify-purchase'. Try it again with quotes:
echo $LE->data->{'verify-purchase'}->item_name;

PHP Call Function from Inside Itself Until Condition Met

I have a function that I am creating that basically connects to the Google Plus API and Pulls information. Unfortunately in order to get more than a few results at a time you need to use the nextPageToken provided in the API callback. Here is what I have so far:
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function parseResults($nextPageToken = "") {
$count = 0;
$content = get_data('https://www.googleapis.com/plus/v1/activities?query=%23throughglass&maxResults=10&orderBy=recent&fields=items(actor(displayName%2Curl)%2Cid%2Cobject(actor%2Cattachments)%2Curl%2Cverb)%2CnextPageToken&pageToken=' . $nextPageToken . '&key=YOUR API KEY HERE');
$posts = json_decode($content);
$token = $posts->nextPageToken;
foreach ($posts->items as $value){
$id = $value->id;
$id_query = mysql_query("SELECT id FROM images WHERE id = '$id'");
if ($value->verb != "post") continue;
if (mysql_num_rows($id_query) > 0) continue;
echo $value->actor->displayName . "<br />";
$count++;
}
if ($count < 20){
parseResults($token);
}else{
break;
}
}
parseResults();
If you can kind of see what I am trying to do here hopefully someone can help me out. I basically want to keep re-calling the parseResults() function with the provided nextPageToken until there have been 20 records processed.
I was able to solve it with help from Lawrence above:
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function parseResults($nextPageToken = "", $count) {
$content = get_data('https://www.googleapis.com/plus/v1/activities?query=%23throughglass&maxResults=10&orderBy=recent&fields=items(actor(displayName%2Curl)%2Cid%2Cobject(actor%2Cattachments)%2Curl%2Cverb)%2CnextPageToken&pageToken=' . $nextPageToken . '&key={YOUR_API_KEY}');
$posts = json_decode($content);
$token = $posts->nextPageToken;
foreach ($posts->items as $value){
$id = $value->id;
$name = $value->actor->displayName;
$profile = $value->actor->url;
$post = $value->url;
$post_text = $value->object->attachments[0]->displayName;
$image_small = $value->object->attachments[0]->image->url;
$image_full = $value->object->attachments[0]->fullImage->url;
$id_query = mysql_query("SELECT id FROM images WHERE id = '$id'");
if (mysql_num_rows($id_query) > 0) continue;
if ($value->verb != "post") continue;
if ($value->object->attachments[0]->image->url == "" || $value->object->attachments[0]->fullImage->url == "") continue;
if ($post_text != "#throughglass") continue;
mysql_query("INSERT INTO images (id,
author_name,
author_url,
post_url,
post_text,
image_small,
image_full) VALUES (
'$id',
'$name',
'$profile',
'$post',
'$post_text',
'$image_small',
'$image_full')");
echo "<b>ID: </b>" . $id . "<br />";
echo "<b>Name: </b>" . $value->actor->displayName . "<br />";
echo "<b>Profile URL: </b>" . $value->actor->url . "<br />";
echo "<b>Post URL: </b>" . $value->url . "<br />";
echo "<b>Post Text: </b>" . $value->object->attachments[0]->displayName . "<br />";
echo "<b>Image Small: </b>" . $value->object->attachments[0]->image->url . "<br />";
echo "<b>Image Full: </b>" . $value->object->attachments[0]->fullImage->url . "<br /><br />";
$count++;
}
if ($count < 100){
parseResults($token, $count);
}else{
echo "<br /><br /><br />" . $token;
break;
}
}
parseResults("", 0);
I think you want to count the number of recursive calls.
You can achive this by wrapping the function into a class an use a class property, but an easiest wayt would be to add a parameter to your function parseResult and increment it before the next call.

JSON and PHP driven slideshow not working

I have inherited a project from a client that uses JSON and PHP to display real estate property listings from a online realty service. The data provided by the service loads, but the properties and agents associated with them get mixed up. Sometimes all of the properties are displayed, but have only one agent associated with them. Other times the data loads, but does not transition after a few properties have been displayed. The transitions are being controlled by the jQuery cycle plugin.
I have included all of the code below. Any assistance is greatly appreciated.
Thank you.
Mike
<?php
function decode_json_string($json){
$objects = array();
$start_pos = strpos($json, '[');
$end_pos = strpos($json, ']');
$dataString = substr($json, ++$start_pos, ($end_pos - $start_pos));
while(strpos($dataString, '{') !== FALSE){
$start_pos = strpos($dataString, '{');
$end_pos = strpos($dataString, '}');
$objectString = substr($dataString, ++$start_pos, ($end_pos - $start_pos));
$tempString = $objectString;
$formattedString = "";
while(strpos($tempString, ':') !== FALSE){
$valueStart = strpos($tempString, ':');
if($tempString[++$valueStart] != '"'){
$substring1 = substr($tempString, 0, $valueStart);
if(strpos($tempString, ',', $valueStart) !== FALSE){
$valueEnd = strpos($tempString, ',', $valueStart);
$substring2 = substr($tempString, $valueStart, ($valueEnd - $valueStart));
}
else{
$valueEnd = $valueStart + 1;
$substring2 = substr($tempString, $valueStart);
}
$formattedString .= $substring1 . '"' . $substring2 . '"';
$tempString = substr($tempString, $valueEnd);
}
else{
$valueEnd = strpos($tempString, '",') + 1;
$formattedString .= substr($tempString, 0, $valueEnd);
$tempString = substr($tempString, $valueEnd);
}
}
$tempArray = explode('",', $formattedString);
foreach($tempArray as $tempValue){
$tempValueArray = explode( ":", $tempValue);
$key = format_string($tempValueArray[0]);
$value = format_string($tempValueArray[1]);
$object[$key] = $value;
}
$objects[] = $object;
$dataString = substr($dataString, ++$end_pos);
}
return $objects;
}
function format_string($string){
$string = str_replace("'", "", $string);
$string = str_replace('"', "", $string);
return trim($string);
}
function get_agent_properties_json($agentID){
global $BASE_URL;
$date = time();
$dataType = '3'; // Data Type = Properties
$url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID . '&agentID=' . $agentID;
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
return $response;
}
function get_agent_properties($agentID){
$agent_properties_json = get_agent_properties_json($agentID);
$properties = decode_json_string($agent_properties_json);
return $properties;
}
function print_property_details(&$property, &$agent){
global $BASE_URL;
if($property['ListingStatusCode'] != 'SOLD'){
$address = $property['Address'];
$shortaddr = substr($address, 0, -12);
echo "<div class='propertySlide'>";
echo "<div class='title'>";
echo "<div class='box1'>";
echo "<span class='price'>". $property['Price'] ."</span>";
echo "<span class='address'>". $shortaddr ."</span>";
echo "</div>";
echo "<div class='box2'>";
echo "<span class='style'><strong>Style:</strong> ". $property['Style'] ."</span>";
echo "<span class='footage'><strong>Sq. Feet:</strong> ". $property['SqFootage'] ."</span>";
echo "<span class='beds'><strong>Beds:</strong> ". $property['Bedrooms'] ."</span>";
echo "<span class='baths'><strong>Baths:</strong> ". $property['Bathrooms'] ."</span>";
echo "<span class='year'><strong>Year Built:</strong> ". $property['YearBuilt'] ."</span>";
echo "</div>";
echo "</div>";
echo "<div class='imagebox'><img class='listingImage' src='". $BASE_URL . $property['Image'] ."' /></div>";
echo "<div class='agentbox'>";
echo "<img class='agentImage' src='" . $BASE_URL . "/Users/pic" . $agent['WTLUserID'] . ".jpg' />";
echo "<span class='agent'><strong>Agent:</strong> ". $agent['DisplayName'] ."</span>";
echo "</div>";
echo "</div>";
}
}
?>
$date = time();
$dataType = '4'; // Data Type = Agents
$companyID = '2119'; // Red Deer - Century 21 Advantage
$url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID;
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$agents = decode_json_string($response);
foreach($agents as $agent){
$properties = get_agent_properties($agent['WTLUserID']);
foreach($properties as $property){
print_property_details($property, $agent);
}
}
<?php
$BASE_URL = 'http://www.century21.ca';
$date = time();
$dataType = '4'; // Data Type = Agents
$companyID = '2119'; // Red Deer - Century 21 Advantage
$url = $BASE_URL . '/FeaturedDataHandler.c?r=' . $date . '&DataType=' . $dataType . '&CompanyID=' . $companyID;
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$agents = decode_json_string($response);
foreach($agents as $agent){
$properties = get_agent_properties($agent['WTLUserID']);
foreach($properties as $property){
print_property_details($property, $agent);
}
}
Before trying to debug the decode_json_string() function here you should try PHP's built-in json_decode() http://php.net/manual/en/function.json-decode.php
If you have an older version of PHP that lacks json_decode() you can find a compatible one in upgrade.php

Categories