Change proxy service on php file - php

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;
}

Related

Running into ERR_CONNECTION_RESET when checking multiple links

I want to write a small PHP script which checks the existence of files on a server.
The files URLs have the following format:
http://update.example.com/Files/Updates/7.25.2.128/application7_25_2_128_de_FullInstallerx64.exe
Now I want to loop through the version numbers and check if the file exists.
function checkAllUrls() {
$revisionNumber = 25;
$minorNumber = 2;
$buildNumber = 128;
for ($x = $buildNumber; $x > 0; $x--) {
file_put_contents('log.txt', "Checking Build: $x", FILE_APPEND);
$combinedUrl = 'http://update.example.com/Files/Updates/6.' . $revisionNumber . '.' . $minorNumber . '.' . $x . '/application7_' . $revisionNumber . '_' . $minorNumber . '_' . $x . '_de_FullInstallerx64.exe';
$urlHeaders = #get_headers($combinedUrl);
if(!$urlHeaders || $urlHeaders[0] == 'HTTP/1.1 404 Not Found') {
$exists = "no";
file_put_contents('log.txt', "\n" . $combinedUrl . " - " . "does not exist. \n", FILE_APPEND);
} else {
$exists = "yes";
file_put_contents('log.txt', "\n" . $combinedUrl . " - " . "exists. \n", FILE_APPEND);
}
sleep(3);
}
}
The problem is, that even if using sleep() with 3 seconds, the links / files are not checked after a couple of links.
Afterwards I cannot open any of the valid links in my browser any more getting ERR_CONNECTION_RESET in return. At first I was afraid, that I kind of crashed the server, but accessing via VPN still lets me download the file.
Can anybody explain to my, why this is happening and how I can avoid this behaviour?
Thanks in advance.
maybe your problem don't use multiple request. Try this multiple curl request method.
function checkAllUrls() {
$revisionNumber = 25;
$minorNumber = 2;
$buildNumber = 128;
$multiCurl = curl_multi_init();
$curlArray = array();
for ($x = $buildNumber; $x > 0; $x--) {
$combinedUrl = 'http://update.example.com/Files/Updates/6.' . $revisionNumber . '.' . $minorNumber . '.' . $x . '/application7_' . $revisionNumber . '_' . $minorNumber . '_' . $x . '_de_FullInstallerx64.exe';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $combinedUrl);
curl_setopt($curl, CURLOPT_FILETIME, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_multi_add_handle($multiCurl,$curl);
$curlArray[] = ['curl' => $curl, 'build' => $x] ;
}
$i = NULL;
do {
$x = curl_multi_exec($multiCurl, $i);
} while ($i > 0);
foreach ($curlArray as $k => $v) {
file_put_contents('log.txt', "Checking Build: ".$v['build'], FILE_APPEND);
$httpCode = curl_getinfo($v['curl'], CURLINFO_HTTP_CODE);
$combinedUrl = curl_getinfo($v['curl'], CURLINFO_EFFECTIVE_URL);
if($httpCode === 404) {
$exists = "no";
file_put_contents('log.txt', "\n" . $combinedUrl . " - " . "does not exist. \n", FILE_APPEND);
} else {
$exists = "yes";
file_put_contents('log.txt', "\n" . $combinedUrl . " - " . "exists. \n", FILE_APPEND);
}
curl_multi_remove_handle($multiCurl, $v['curl']);
}
curl_multi_close($multiCurl);
}

how to send curl request for delete image from s3 bucket in php

function S3_delete($s3_array)
{
$AWSAccessKeyId = 'youraccesskey';
$AWSSecretAccessKey = 'yoursecretaccesskey';
$BucketName = 'yourbucket';
$AWSRegion = 'ap-south-1';
$canonical_uri="/images/coupon_images/medium_banner/2019091810352344157.jpg";
$encoded_uri = str_replace('%2F', '/', rawurlencode($canonical_uri));
if($AWSRegion == 'us-east-1') {
$hostname = trim($BucketName .".s3.amazonaws.com");
$header_string = "host:" . $hostname . "\n";
$signed_headers_string = "host";
} else {
$hostname = trim($BucketName . ".s3-" . $AWSRegion . ".amazonaws.com");
$header_string = "host:" . $hostname . "\n";
$signed_headers_string = "host";
}
$date_text = gmdate('Ymd', time());
$time_text = gmdate('Ymd\THis\Z');
$algorithm = 'AWS4-HMAC-SHA256';
$scope = $date_text . "/" . $AWSRegion . "/s3/aws4_request";
$x_amz_params = array(
'X-Amz-Algorithm' => $algorithm,
'X-Amz-Credential' => $AWSAccessKeyId . '/' . $scope,
'X-Amz-Date' => $time_text,
'X-Amz-SignedHeaders' => $signed_headers_string
);
$expires = 72000;
if ($expires > 0) {
$x_amz_params['X-Amz-Expires'] = $expires;
}
ksort($x_amz_params);
$query_string = "";
foreach ($x_amz_params as $key => $value) {
$query_string .= rawurlencode($key) . '=' . rawurlencode($value) . "&";
}
$query_string = substr($query_string, 0, -1);
$canonical_request = "DELETE\n" . $encoded_uri . "\n" . $query_string . "\n" . $header_string . "\n" . $signed_headers_string . "\nUNSIGNED-PAYLOAD";
$string_to_sign = $algorithm . "\n" . $time_text . "\n" . $scope . "\n" . hash('sha256', $canonical_request, false);
$signing_key = hash_hmac('sha256', 'aws4_request', hash_hmac('sha256', 's3', hash_hmac('sha256', $AWSRegion, hash_hmac('sha256', $date_text, 'AWS4' . $AWSSecretAccessKey, true), true), true), true);
$signature = hash_hmac('sha256', $string_to_sign, $signing_key);
$url = 'https://' . $hostname . $encoded_uri . '?' . $query_string . '&X-Amz-Signature=' . $signature;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
return $httpcode = curl_getinfo($ch);
}
above code give response like this,
SignatureDoesNotMatchThe request signature we calculated does not
match the signature you provided. Check your key and signing
method.AKIAJKLJAHRPH4X4FSMQAWS4-HMAC-SHA256 20190919T053115Z
20190919/ap-south-1/s3/aws4_request
100% work the below code..
S3_delete('201909251745545.jpg','imagesbook/post_blog/'); //call function
function S3_delete($filename,$path)
{
$file_name = $filename;
$file_delete_path = $path;
$aws_access_key_id = 'your-accress-key';
$aws_secret_access_key = 'your-secret-access-key';
$bucket_name = 'your-bucket-name';
$aws_region = 'your-region'; // Enter your aws region Ex. us-east-1
$host_name = $bucket_name . '.s3.amazonaws.com';
$content_acl = 'public-read';
$content_type = '';
$content='';
$content_title = $file_delete_path.$file_name;
$aws_service_name = 's3';
$timestamp = gmdate('Ymd\THis\Z');
$date = gmdate('Ymd');
$request_headers = array();
$request_headers['Content-Type'] = $content_type;
$request_headers['Date'] = $timestamp;
$request_headers['Host'] = $host_name;
$request_headers['x-amz-acl'] = $content_acl;
$request_headers['x-amz-content-sha256'] = hash('sha256',"");
ksort($request_headers);
$canonical_headers = [];
foreach($request_headers as $key => $value)
{
$canonical_headers[] = strtolower($key) . ":" . $value;
}
$canonical_headers = implode("\n", $canonical_headers);
$signed_headers = [];
foreach($request_headers as $key => $value)
{
$signed_headers[] = strtolower($key);
}
$signed_headers = implode(";", $signed_headers);
$canonical_request = [];
$canonical_request[] = "DELETE";
$canonical_request[] = "/" . $content_title;
$canonical_request[] = "";
$canonical_request[] = $canonical_headers;
$canonical_request[] = "";
$canonical_request[] = $signed_headers;
$canonical_request[] = hash('sha256', $content);
$canonical_request = implode("\n", $canonical_request);
$hashed_canonical_request = hash('sha256', $canonical_request);
$scope = [];
$scope[] = $date;
$scope[] = $aws_region;
$scope[] = $aws_service_name;
$scope[] = "aws4_request";
$string_to_sign = [];
$string_to_sign[] = "AWS4-HMAC-SHA256";
$string_to_sign[] = $timestamp;
$string_to_sign[] = implode('/', $scope);
$string_to_sign[] = $hashed_canonical_request;
$string_to_sign = implode("\n", $string_to_sign);
$kSecret = 'AWS4' . $aws_secret_access_key;
$kDate = hash_hmac('sha256', $date, $kSecret, true);
$kRegion = hash_hmac('sha256', $aws_region, $kDate, true);
$kService = hash_hmac('sha256', $aws_service_name, $kRegion, true);
$kSigning = hash_hmac('sha256', 'aws4_request', $kService, true);
$signature = hash_hmac('sha256', $string_to_sign, $kSigning);
$authorization = [
'Credential=' . $aws_access_key_id . '/' . implode('/', $scope),
'SignedHeaders=' . $signed_headers,
'Signature=' . $signature
];
$authorization = 'AWS4-HMAC-SHA256' . ' ' . implode( ',', $authorization);
$curl_headers = [ 'Authorization: ' . $authorization ];
foreach($request_headers as $key => $value)
{
$curl_headers[] = $key . ": " . $value;
}
$url = 'https://' . $host_name . '/' . $content_title;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
return curl_exec($ch); // return response data 1
//$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//curl_close($ch);
//return $httpcode;
}

Sage Pay Reporting API - generated signature hash not valid

I am trying to invoke the getTransactionDetail end point on sagepay reporting api (https://www.sagepay.co.uk/file/6946/download-document/Reporting_and_Admin_API_Integration_Guideline_31012014.pdf) and the signature I made as per the following instructions:
does not appear to be working, I am getting an invalid signature response.
Here's what I have tried so far:
<?php
$vendor = 'myvendername';
$username = 'my-username';
$password = 'my-password';
$vpstxid = '{my-vpstxid-guid-here}';
$request = [
'command' => 'getTransactionDetail',
'vendor' => $vendor,
'user' => $username,
'vpstxid' => $vpstxid,
];
$signature = _calculate_request_signature($request);
$request_xml = _build_sagepay_request($request, $signature);
$result = _call_sagepay_server('https://test.sagepay.com/access/access.htm', $request_xml);
$xml = simplexml_load_string($result);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
echo '<pre>'; print_r($array); exit;
function _calculate_request_signature($data) {
global $password;
$req = '';
foreach ($data as $key => $value) {
$req .= '<' . $key . '>' . $value . '</' . $key . '>' . PHP_EOL;
}
$req .= '<password>' . $password . '</password>';
return md5($req);
}
function _build_sagepay_request($data, $signature) {
$result = '<vspaccess>' . PHP_EOL;
foreach ($data as $key => $value) {
$result .= "\t" . '<' . $key . '>' . $value . '</' . $key . '>' . PHP_EOL;
}
$result .= "\t" . '<signature>' . $signature . '</signature>' . PHP_EOL;
$result .= '</vspaccess>';
return $result;
}
function _call_sagepay_server($url, $request_xml)
{ ... snipped ... }
Any ideas?
Ok, I've figured it out:
No tabs / PHP_EOL in the request / signature calc, keep it flat one line xml and it works.
function _calculate_request_signature($data) {
global $password;
$req = '';
foreach ($data as $key => $value) {
$req .= '<' . $key . '>' . $value . '</' . $key . '>';
}
$req .= '<password>' . $password . '</password>';
return strtoupper(md5($req));
}
function _build_sagepay_request($data, $signature) {
$result = '<vspaccess>';
foreach ($data as $key => $value) {
$result .= '<' . $key . '>' . $value . '</' . $key . '>';
}
$result .= '<signature>' . $signature . '</signature>';
$result .= '</vspaccess>';
return $result;
}
function _call_sagepay_server($url, $request_xml)
{
global $lastCurlError;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'XML=' . $request_xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 45);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$lastCurlError = curl_errno($curl);
curl_close($curl);
return $result;
}

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;

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