ob_start();
header('Content-Type:text/html; charset=UTF-8');
$strRoot="";
include $strRoot."include/Connection.inc";
$URIRedirectID=hexdec($redirect);
$domain="http://environmentalchemistry.com";
$URI="/";
$RedirectURL=$domain.$URI;
if ($dbR==""){
$lines = file($strRoot."include/WriteableFiles/URLRedirect.txt");
$URLRedirectRows=0;
foreach ($lines as $line_num => $line) {
$lineprep="";
$lineprep=explode("|",$line);
if($line_num>0){
$i = 0;
$tempRedirectID=$lineprep[0];
if($lineprep[0]="M"){
$RedirectURL="http://EnvironmentalChemistry.com".trim($lineprep[2]);
}
else{
$RedirectURL="http://blog.EnvironmentalChemistry.com".trim($lineprep[2]);
}
$arrayURLRedirect[$tempRedirectID]=$RedirectURL;
}
}
unset($lines);
unset($tempRedirectID);
unset($RedirectURL);
unset($line_num);
unset($lineprep);
if($arrayURLRedirect[$URIRedirectID]!=""){
$domainURI=$arrayURLRedirect[$URIRedirectID];
}
}
elseif($URIRedirectID>0 && $URIRedirectID<10000000){
$sql="SELECT * FROM tblURLRedirect WHERE URLRedirectID=$URIRedirectID LIMIT 1";
$result=mysqli_query($dbR,$sql);
$num = mysqli_num_rows($result);
$RedirectURI="";
if($num==1){
$row = mysqli_fetch_array($result);
if($row['Site']=="M"){$domain="http://environmentalchemistry.com";}
else{$domain="http://blog.environmentalchemistry.com";}
$URI=stripslashes($row['URI']);
$ClickThrus=$row['ClickThrus'];
mysqli_free_result($result);
$ClickThrus++;
$sql="UPDATE tblURLRedirect SET ClickThrus=$ClickThrus WHERE URLRedirectID=$URIRedirectID;";
$result=mysqli_query($dbW,$sql);
$RedirectURL=$domain.$URI;
}
else{
mysqli_free_result($result);
}
}
header("HTTP/1.1 301 Moved Permanently");
header("Location: $RedirectURL");
if(isset($dbR)){mysqli_close($dbR);}
if(isset($dbW)){mysqli_close($dbW);}
?>