Wine Store

Author: monchster

///////////////////////////////////////////////////////////
// The server access method determines which PHP function
// this code uses to get data from the feed server.
//
// By default, the method used is the fopen function. If
// your web host has disabled this method, you can try the
// fsockopen and cURL methods.
//
// The cURL method is not enabled in PHP by default but is
// the fastest data access method.
//
// To change the access method, change the setting below
// to one of the following values:
// 0 = fopen
// 1 = fsockopen
// 2 = cURL
///////////////////////////////////////////////////////////

$serverAccessMethod = 0;

$fsAgent = urlencode($_SERVER['HTTP_USER_AGENT']);
$fsIP = urlencode($_SERVER['REMOTE_ADDR']);
$fsPageURL = urlencode($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
$fsURL = 'http://fssrv.com/ezstore.aspx?rs=1&cl=2&sid=8940&adid=61&ak=383647631377&afid=5TuKRvU0BR0&ver=1&ps=12&tw=550px&bc=669900&bgc=65411E&bs=1&f=Arial%2CHelvetica%2Csans-serif&fs=12px&fsd=11px&si=1&sd=1&sr=1&so=1&sp=1&sc=1&sbn=1&ss=1&nw=1&pl=1&ppr=3&ds=1&is=2&l=1&fid=63&kt=2';
$fsURL .= '&agent='.$fsAgent;
$fsURL .= '&ip='.$fsIP;
$fsURL .= '&url='.$fsPageURL;
echo getData($fsURL, $serverAccessMethod);

function getData($url, $serverAccessMethod){
if ($serverAccessMethod == 0) {
$data = getDataViaFopen($url);
}
elseif ($serverAccessMethod == 1) {
$data = getDataViaFsockopen($url);
}
elseif ($serverAccessMethod == 2) {
$data = getDataViaCURL($url);
}

if ($data == 'connection_error') {
$accessMethodName = getDataAccessMethodName($serverAccessMethod);

echo 'Unable to access the feed server. Your web host does not have the "'.$accessMethodName.'" function enabled.
‘;
echo ‘Please select one of the other access methods or ask your web host to enable the “‘.$accessMethodName.’” PHP function

‘;
echo ‘Please see the instructions at the top of this PHP code for details on changing the access method.’;

exit;
}
else {
return $data;
}
}

function getDataViaFopen($url){
$file_handle = fopen ($url, “r”);
if (!$file_handle) {
return ‘connection_error’;
}
else {
while (!feof($file_handle)) {
$file_contents .= fread($file_handle, 8192);
}
fclose($file_handle);
return $file_contents;
}
}

function getDataViaFsockopen( $url ) {
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0) $port = 80;
$path = $url_parsed["path"];

// Add a trialing forward slash. Some web servers get 400 err if there isn’t one
$path = addTrailingSlash($path);

$out = “GET $path HTTP/1.0\r\nHost: $host\r\nConnection: close\r\n\r\n”;
$fp = fsockopen($host, $port, $errno, $errstr, 30);

if (!$fp) {
return ‘connection_error’;
} else {
fwrite($fp, $out);

// Remove the header
do $header.=fread($fp,1); while (!preg_match(‘/\\r\\n\\r\\n$/’,$header));

while (!feof($fp)) {
$file_contents .= fgets($fp, 8192);
}
fclose($fp);
return $file_contents;
}
}

function getDataViaCURL($url){
$url_parsed = parse_url($url);

// Add a trialing forward slash. Some web servers get 400 err if there isn’t one
$path = addTrailingSlash($path);

$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $path); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, 80); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 40); // times out

$file_contents = curl_exec($ch);
curl_close($ch);

return $file_contents;
}

function addTrailingSlash($url) {
$url_parsed = parse_url($url);
$path = $url_parsed["path"];
if (empty($path)) $path=”/”;
return $path;
}

function getDataAccessMethodName($accessMethod) {
if ($gc_ServerAccessMethod == 0) {
return ‘fopen’;
}
elseif ($gc_ServerAccessMethod == 1) {
return ‘fsockopen’;
}
elseif ($gc_ServerAccessMethod == 2) {
return ‘cURL’;
}
}
?>