Functions
AddHeader
AddHeader ( string $name, string $value )
Set a header for the session. Must be called before Connect()
Parameters
name
Header name to be passed.
Required:
value
Required:
- RETS-Version - Valid and supported RETS version
- User-Agent - Name of your program
Header value to be passed.
Return Values
None
Examples
$rets->AddHeader("Accept", "*/*");$rets->AddHeader("RETS-Version", "RETS/1.5");$rets->AddHeader("User-Agent", "PHRETS/1.0");Connect
Connect ( string $login_url, string $username, string $password [, string $ua_pwd ] )
Makes initial RETS Login connection. If RETS 'Action' exists, performs that request as well.
Parameters
login_url
Full Login URL to the RETS server
username
Login username
password
Login password
ua_pwd
Optional. User-Agent Password.
Default is blank. If not blank, User-Agent Authentication is forced.
Default is blank. If not blank, User-Agent Authentication is forced.
Return Values
None
Examples
Connects
Connects with User-Agent Authentication
$rets->Connect("http://demo.crt.realtors.org:6103/rets/login",
"Joe",
"Schmoe"
);
$rets->Connect("http://demo.crt.realtors.org:6103/rets/login",
"Joe",
"Schmoe",
"ua-password"
);
Related to
GetObject
GetObject ( string $resource, string $type, string $id [, string $object-id [, string $location ]] )
Makes RETS request to receive objects (typically photos)
Parameters
resource
RETS Resource for requested object
Example Values:
type
Example Values:
- Property
- Agent
- Office
RETS GetObject Resource as defined by RETS.
Example Values:
id
Example Values:
- Photo
- Plat
- Video
- Audio
- Thumbnail
- Map
- VRImage
ID of Object. This is the value of the KeyName field within the Resource for your record (typically the MLS#). This is NOT the full ID as described in the RETS specification.
object-id
Optional. Requested object ID. Typically represents the photo order.
Possible Values: 0, 1, 2, 3, etc., or * (asterisk) to request all objects. Default is *
location
Possible Values: 0, 1, 2, 3, etc., or * (asterisk) to request all objects. Default is *
Optional. Used to return URLs rather than image data. Not always supported by the server. 1 is True, 0 is False. Default is 0.
Return Values
Array
Each item in this array represents a single image that was returned. If multiple images requested, multiple array keys exist and the server may return these in any order.
Possible item contents:
Possible item contents:
Success - Boolean. True if the specific response is successful. False if not.
Content-ID - Content-ID for this specific object.
Object-ID - Object-ID for this specific object (typically represents the display order)
Content-Type - Content-Type for this specific object.
MIME-Version - MIME-Version of this object.
Content-Description - Text description of this object.
Location - Returned if Location is True and server supports. Contains URL to object
Length - Size of data response
Data - Contains the response. If requested Location as False, this is raw image data.
ReplyCode - If Success is False, this contains the RETS ReplyCode returned.
ReplyText - If Success is False, this contains the RETS ReplyText returned.
Content-ID - Content-ID for this specific object.
Object-ID - Object-ID for this specific object (typically represents the display order)
Content-Type - Content-Type for this specific object.
MIME-Version - MIME-Version of this object.
Content-Description - Text description of this object.
Location - Returned if Location is True and server supports. Contains URL to object
Length - Size of data response
Data - Contains the response. If requested Location as False, this is raw image data.
ReplyCode - If Success is False, this contains the RETS ReplyCode returned.
ReplyText - If Success is False, this contains the RETS ReplyText returned.
Examples
Pulls all photos for LN000001
Pulls all photo URLs for LN000001
Pull URL for LN000001's #2 photo
$photos = $rets->GetObject("Property", "Photo", "LN000001");
foreach ($photos as $photo) {
if ($photo['Success'] == true) {
file_put_contents("image-{$photo['Content-ID']}-{$photo['Object-ID']}.jpg", $photo['Data']);
}
else {
echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
}
}
$photos = $rets->GetObject("Property", "Photo", "LN000001", '*', 1);
foreach ($photos as $photo) {
if ($photo['Success'] == true) {
echo "Image {$photo['Object-ID']} for {$photo['Content-ID']} is at {$photo['Location']}\n";
}
else {
echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
}
}
$photos = $rets->GetObject("Property", "Photo", "LN000001", 2, 1);
foreach ($photos as $photo) {
if ($photo['Success'] == true) {
echo "Image {$photo['Object-ID']} for {$photo['Content-ID']} is at {$photo['Location']}\n";
}
else {
echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
}
}
Search
Search ( string $resource, string $class, string $query [, array $optional_params ] )
Makes RETS Search request
Parameters
resource
RETS Resource.
Example Values:
class
Example Values:
- Property
- Agent
- Office
RETS Class.
See the server's metadata for possible values.
query
See the server's metadata for possible values.
DMQL Query passed to the server
optional_params
Optional. Associative array of parameters which represent name-value pairs of RETS settings. See RETS specification for specific options.
Return Values
Array
Each item in this array represents a single record that was returned as an associative array. Keys and values of that associative array are name-value pairs for each field.
Examples
Search all residential properties where the Listing Date is 01/01/1990 or after
Everything plus the kitchen sink
$search = $rets->Search("Property","ResidentialProperty","(LD=1990-01-01+)");
foreach ($search as $listing) {
echo "Address: {$listing['STNUM']} {$listing['STNAME']}, ";
echo "{$listing['CITY']}, ";
echo "{$listing['STATE']} {$listing['ZIPCODE']} listed for ";
echo "\$".number_format($listing['LP'])."\n";
}
Address: 83 Fox Hill, Buffalo Grove, IL 60089 listed for $380,000 Address: 1250 Armitage Ave, Chicago, IL 60613 listed for $250,000 Address: 430 Michigan Ave, Chicago, IL 60605 listed for $300,000 Address: 625 Michigan, Chicago, IL 60605 listed for $250,000 Address: 120 Main St, Evanston, IL 60533 listed for $425,000
$search = $rets->Search("Property","ResidentialProperty","(ListDate=1990-01-01+)", array( 'Count' => 1, 'Format' => 'COMPACT', 'Limit' => 2, 'Offset' => '2', 'Select' => 'StreetNumber,StreetName,ListPrice,City,StateOrProvince,PostalCode', 'RestrictedIndicator' => '****', 'StandardNames' => 1 ));
foreach ($search as $listing) {
echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
echo "{$listing['City']}, ";
echo "{$listing['StateOrProvince']} {$listing['PostalCode']} listed for ";
echo "\$".number_format($listing['ListPrice'])."\n";
}
Address: 1250 Armitage Ave, Chicago, IL 60613 listed for $250,000 Address: 430 Michigan Ave, Chicago, IL 60605 listed for $300,000
Related to
SetParam
SetParam ( string $name, string $value )
Sets a parameter for the session. Must be called before Connect()
Parameters
name
Parameter name.
Possible Values:
value
Possible Values:
- cookie_file - Path to file to use for temporary session information storage
- debug_mode - Sets cURL output to verbose if True. Default is False.
- compression_enabled - Enables GZIP compression if True. Default is False.
- force_ua_authentication - Forces UA authentication when True. Default is False.
- disable_follow_location - In case of PHP safe_mode errors, set to True. Default is False.
Parameter value. See above
Return Values
None
Examples
$rets->SetParam("cookie_file", "phrets_cookies.txt");$rets->SetParam("debug_mode", true);$rets->SetParam("compression_enabled", true);$rets->SetParam("force_ua_authentication", true);$rets->SetParam("disable_follow_location", true);Related to
IsMaxrowsReached
IsMaxrowsReached ( )
Used to determine if the previously requested Search() has more records than the number returned.
Parameters
None
Return Values
True if returned records is fewer than total matching query. False otherwise.
Examples
if ($rets->IsMaxrowsReached()) {
// server has more records than just returned.
// if server supports Offset, you can move to the next "page" of results.
// for example, if previous search only returned 100 with no Offset,
// do Search again but with Offset=101 to get the next 100 records.
// if IsMaxrowsReached is true again,
// do Search again but with Offset=201 to get next 100, etc. until
// IsMaxrowsReached() is false.
// include check to catch infinite loop if server doesn't support Offset
// since IsMaxrowsReached will always be true and you're redownloading
// the same records over and over and over
}
else {
// last query returned everything so continue on
}
Related to
TotalRecordsFound
TotalRecordsFound ( )
Returns number of records server says matches query from previous Search(). If your Search() request included Count=1, this number may just be the number of records returned in the response or may be the total number of records that match your query (caused by an ambiguity in the RETS specification and dependant on server implementor). Search() with Count=0 will not return this value. Search() with Count=2 will return a value representing all matching records with no records.
Parameters
None
Return Values
Integer representing 'Count' reported by server
Examples
if ($rets->TotalRecordsFound() > 1000) {
// server reports more than 1000
}
Related to
NumRows
NumRows ( )
Returns number of records included in response from previous Search().
Parameters
None
Return Values
Integer representing number of records returned
Examples
if ($rets->NumRows() > 1000) {
echo "More than 1,000 rows returned in last response.\n";
}
Related to
Disconnect
Disconnect ( )
Logs out from RETS server and cleans up temporary files used by PHRETS.
Parameters
None
Return Values
None
Examples
$rets->Disconnect();
Related to
Examples
This demonstrates the low level framework within PHRETS.
Connect(login_url, username, password) starts thing up and makes the initial RETS login using cURL.
RETSRequest(capability_name, parameters) makes the RETS request using the given transaction and arguments. Returns HTTP headers and XML from server.
Disconnect() logs out from the RETS server and cleans up.
require "phrets.php";
$rets = new phRETS;
$rets->AddHeader("Accept", "*/*");
$rets->AddHeader("RETS-Version", "RETS/1.5");
$rets->AddHeader("User-Agent", "PHRETS/1.0");
$rets->SetParam("cookie_file", "phrets_cookies.txt");
//$rets->SetParam("debug_mode", TRUE); // ends up in rets_debug.txt
$rets->Connect("http://demo.crt.realtors.org:6103/rets/login", "Joe", "Schmoe");
list($headers,$body) = $rets->RETSRequest($rets->capability_url['GetMetadata'],
array(
'Type' => 'METADATA-CLASS',
'ID' => 0,
'Format' => 'STANDARD-XML'
)
);
// $headers includes HTTP headers
// $body includes the XML response
list($headers,$body) = $rets->RETSRequest($rets->capability_url['GetMetadata'],
array(
'Type' => 'METADATA-TABLE',
'ID' => "Property:ResidentialProperty",
'Format' => 'STANDARD-XML'
)
);
// $headers includes HTTP headers
// $body includes the XML response
list($headers,$body) = $rets->RETSRequest($rets->capability_url['GetMetadata'],
array(
'Type' => 'METADATA-LOOKUP_TYPE',
'ID' => 'Property:IFT'
)
);
// $headers includes HTTP headers
// $body includes the XML response
list($headers,$body) = $rets->RETSRequest($rets->capability_url['Search'],
array(
'Query' => '(LP=0-999999999)',
'QueryType' => 'DMQL2',
'Limit' => 2,
'SearchType' => 'Property',
'Class' => 'ResidentialProperty',
'Format' => 'COMPACT-DECODED',
'StandardNames' => 0
)
);
// $headers includes HTTP headers
// $body includes the XML response
list($headers,$body) = $rets->RETSRequest($rets->capability_url['GetObject'],
array(
'Resource' => 'Property',
'Type' => 'Photo',
'Location' => 0,
'ID' => 'LN000001:*')
);
// $headers includes HTTP headers
// $body includes the response
$rets->Disconnect();
Example
This shows some of the high level features and how you'd interact with them. These use the RETSRequest() function behind-the-scenes. More capabilities to come
require "phrets.php";
$rets = new phRETS;
$rets->AddHeader("Accept", "*/*");
$rets->AddHeader("RETS-Version", "RETS/1.5");
$rets->AddHeader("User-Agent", "PHRETS/1.0");
$rets->SetParam("cookie_file", "phrets_cookies.txt");
$rets->Connect("http://demo.crt.realtors.org:6103/rets/login", "Joe", "Schmoe");
$rets_metadata_types = $rets->GetMetadataTypes();
foreach ($rets_metadata_types as $resource) {
echo "Resource: {$resource['Resource']}\n";
foreach ($resource['Data'] as $class) {
echo " + Class: {$class['ClassName']}\n";
$rets_metadata = $rets->GetMetadata($resource['Resource'],$class['ClassName']);
foreach ($rets_metadata as $field) {
echo " + Field: {$field['SystemName']} ({$field['DataType']})\n";
}
}
}
$search = $rets->Search("Property","ResidentialProperty","(LD=1990-01-01+)");
foreach ($search as $listing) {
echo "Address: {$listing['STNUM']} {$listing['STNAME']}, ";
echo "{$listing['CITY']}, ";
echo "{$listing['STATE']} {$listing['ZIPCODE']} listed for ";
echo "\$".number_format($listing['LP'])."\n";
}
$photos = $rets->GetObject("Property", "Photo", "LN000001", '*', 1);
foreach ($photos as $photo) {
if ($photo['Success'] == true) {
echo "Image {$photo['Object-ID']} for {$photo['Content-ID']} is at {$photo['Location']}\n";
}
else {
echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
}
}
$rets->Disconnect();
Logs in (Connect), learns what data is available (GetMetadataTypes), retrieves data formats for each data type found (GetMetadata) and echos all fields within those types.
