/* ___________________________________
* IDX Broker idxco.com Domain Cloaker
*
* NOTE: We will not be providing any support for this program.
* Before making this live on your site, it is recommended that you browse through
* all of the IDX pages using this script to make sure everything works properly.
* Using this will not affect your sub-domain pages on idxco.com. If this program doesnt work you
* can still use te idxco sub-domain as usual.
*
* WHAT THIS SCRIPT DOES:
* You will be able to serve IDX pages on your site without the subdomain idxco.com in the URL.
* For example this will point:
* www.yoursite.com/idx/basicSearch.php to www.yoursite.idxco.com/idx/1234/basicSearch.php
* The end result is that it will appear to your visitors that all of the IDX content is on your domain.
*
* TO USE THIS SCRIPT YOUR MUST:
* 1.) Put it in the root web directory of your site. (ex: www.yourdomain.com/thisScript.php)
* 2.) You must also have mod_rewrite(http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html) enabled
* 3.) Must have php CURL(http://us3.php.net/curl) enabled on your server.
* 4.) Create a folder somewhere on your server called cookies and CHMOD it 777
* Do this outside of the WWW directory if you can...
* 5.) You must add the following lines to your .htaccess file or use the .htaccess file supplied:
* Options +FollowSymlinks
* RewriteEngine on
* RewriteRule ^idx/(.*) cloakURL.php
*
* Note: The word 'idx' can be changed, but must match the defined 'IDX_DIRECTORY' below.
* CloakURL.php is the name of this file and can be changed to anything as long as it
* remains in the root web directory and the file name corresponds to your RewriteRule
* in .htaccess.
* 6.) Change the variables below to match your IDX account and website information.
* Follow the pre-filled examples to make sure you get the variables correct.
* 7.) Update your Google Maps API Key to match your own domain without idxco.com if you use map searches
*
* If you set the variable 'SHOW_ROOT' to true below you will get a bit of help finding the full path
* to your web directory on your server and a full path to the cookies directory you should create.
*/
/* Define Constant Variables */
define(CLIENT_ID,'3036'); //--- Your IDX Client ID
define(CLIENT_SUB_DOMAIN,'mountsnowpalmiter'); //--- Your IDX Sub-Domain (NO . MARKS)
define(CLIENT_DOMAIN,'mountsnowpalmiter.com'); //--- Your domain (with TLD) without the http:// or www.
define(IDX_DIRECTORY,'idx'); //--- The 'virtual' directory that you want all of your IDX pages to be in
define(GMAP_KEY,'ABQIAAAA5TLUZNEg-_l1LtzKEnDKYBQDEFEVd4Qzvx4MNhTV_1oMhghzHhTVPzyK0atdYgkemTst53DOYhrHbA'); //google maps API key
define(COOKIE_DIR, '/home/content/a/p/a/apalmiter/html/cookiedir/'); //--- Choose a directory to store cookies, put the full path on your server
// to this directory here with the / on both sides. You must also
// CHMOD it 777
define(SHOW_ROOT, FALSE); //--- Set this to true to find the full path to your folder on the server
/* ---- DONT EDIT BELOW HERE ---- */
/* Help user find the full path to their directory on the server */
if(SHOW_ROOT)
{
echo 'The full path to your web directory is: ' . $_SERVER['DOCUMENT_ROOT'] . '
';
echo "This is the full path to your web directory on your server. If you can, put your \"cookies\" folder up 1 level from your live web folder (www, htdocs, public_html, etc..)";
$tmp = explode("/",$_SERVER['DOCUMENT_ROOT']); //build out what could work as their cookies directory
$tmpCount = count($tmp);
$dirStr = "/";
for($i=0;$i<$tmpCount-1;$i++)
$dirStr.= $tmp[$i] . "/";
$dirStr = str_replace("//","/",$dirStr . 'cookies/');
echo "
The cookies directory you make should look something like this: '$dirStr'
";
die();
}
/* If a form is submitted, we need to post these to the URL we access */
if($_POST)
{
$postVars =''; //Flush
foreach($_POST as $k=>$v)
{
$postVars .= $k . "=" .$v . "&"; //Build a GET style string for posting
//echo "post: $k - $v
";
}
$postVars = substr($postVars,0,-1); //Remove trailing & character
}
/* Detect which IDX page is being accessed and remove the prefixes from it */
$page = str_replace("/". IDX_DIRECTORY . "/","",$_SERVER['REQUEST_URI']);
/* Build the full URL path to the corresponding IDX Page */
$url = 'http://' . CLIENT_SUB_DOMAIN . '.idxco.com/idx/' . CLIENT_ID . '/' . $page;
/* Open URL and store contents to an array */
$ch = curl_init(); // initialize CURL
$timeout = 0; // set to zero for no timeout
$cookie = COOKIE_DIR . 'cookie-'. str_replace(".","",$_SERVER['REMOTE_ADDR']) . '.txt'; //set cookie path, IP address for unique
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // required for many of the IDX pages
curl_setopt($ch, CURLOPT_URL, $url); // url at to open
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // yes to allow some editing before output
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //set timeout
curl_setopt($ch, CURLOPT_POST, 1); // post?
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars); // vars to be posted
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // sets the cookie file location
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); // this says to start a new cookie file.
//curl_setopt($ch, CURLOPT_COOKIE, $cookie); // use the cookie we have on file
$file_contents = curl_exec($ch);
curl_close($ch);
$lines = array();
$lines = explode("\n", $file_contents); // load html into a file
/* Output the file line by line while re-routing the links to match your domain */
foreach($lines as $line_num => $line)
{
/* Reproduce each link on the site to point to your server instead of the idxco.com pages */
$line = preg_replace("/\&key=(.*)\" type=/",
"&key=".GMAP_KEY."\" type=",
$line);
$line = str_replace("http://idxco.com/idx/" . CLIENT_ID . "/",
"http://" .CLIENT_DOMAIN . "/" . IDX_DIRECTORY . "/",
$line);
$line = str_replace("http://www.idxco.com/idx/" . CLIENT_ID . "/",
"http://www." .CLIENT_DOMAIN . "/" . IDX_DIRECTORY . "/" ,
$line);
$line = str_replace("http://www." . CLIENT_SUB_DOMAIN . ".idxco.com/idx/" . CLIENT_ID . "/",
"http://www." .CLIENT_DOMAIN . "/" . IDX_DIRECTORY . "/" ,
$line);
$line = str_replace("http://" . CLIENT_SUB_DOMAIN . ".idxco.com/idx/" . CLIENT_ID . "/",
"http://www." .CLIENT_DOMAIN . "/" . IDX_DIRECTORY . "/",
$line);
$line = str_replace("/idx/" . CLIENT_ID . "/",
"/" . IDX_DIRECTORY . "/",
$line);
$line = str_replace('src="/javascript',
'src="http://idxco.com/javascript',
$line);
print $line . " \n"; //print the HTML after going through link filters
}
?>