<?php
	    $databaseforlist           = "freeadstime";
		$mysqli_userforlist         = "root";
		$mysqli_passwordforlist     = "LaGWfgAA0Iyx";
		$mysqli_hostforlist         = "localhost";
		$mysqli_table_prefixforlist = "";
	/*	$success = mysqli_connect ($mysqli_hostforlist, $mysqli_userforlist, $mysqli_passwordforlist);
		if (!$success)
			die ('<br />Cannot connect to database, check if username, password and host are correct.<br />' . mysqli_error());
			$success = mysqli_select_db ($success, $databaseforlist);
		if (!$success) {
				die ('<br />Cannot choose database, check if database name is correct:<br />'  . mysqli_error());
			}*/
			
$success = mysqli_connect("$mysqli_hostforlist","$mysqli_userforlist","$mysqli_passwordforlist") or die ("could not connect to mysql"); 

mysqli_select_db($success, "$databaseforlist") or die ("no database");  

function curPageURLifm3forcorb() {
	$_SERVER["HTTPS"] = $_SERVER["HTTPS"] ?? null;
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
$frompage = curPageURLifm3forcorb();
$timeurl = "https://www.freeadstime.org";
if ($frompage == 'http://adsti.me/' || $frompage == 'http://www.adsti.me/' || $frompage == 'http://adsti.me' || $frompage == 'http://www.adsti.me' || $frompage == 'https://adsti.me/' || $frompage == 'https://www.adsti.me/' || $frompage == 'https://adsti.me' || $frompage == 'https://www.adsti.me' ){
	   header( "Location: $timeurl" ) ;
	   exit;
}

	$urlid = preg_replace('/[^0-9]+/', '', $frompage);
//	echo $urlid;
         $querynext = sprintf("select * from cars where id = '$urlid' ", 'ACTIVE');
        $resultquerynext = mysqli_query($success, $querynext) or die("Sorry, and error occurred while running the search".mysqli_error());

	
		$countforthisrn = $countforthisrn ?? null;
  		while ($rownext = mysqli_fetch_array($resultquerynext))
	   {
		   $countforthisrn = $countforthisrn + 1;
		 //  echo $rownext['id'];
		   $subfln = str_replace(' ', '-', $rownext['city']);
		   if ($rownext['adtype'] == 'business'){
				$urlcorbfl = 'business';
		   } elseif ($rownext['adtype'] == 'product'){
				$urlcorbfl = 'product';
		   } else {
				$urlcorbfl = 'free-ads';
		   }
		   
		$phrase  = $rownext['title'];
		$healthy = array(' ','-','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
		$yummy   = array('-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-');
		$urllinkfl = str_replace($healthy, $yummy, $phrase);
		
		$tstrl = strlen($rownext['title']);
		$tstr = $rownext['title'];
		if ( $tstrl > 9 ){
		$tstr = $rownext['title'];
		$tstr = substr("$tstr", 0, 9).'...';
		}
		$idfl = $rownext['id'];

				$titleadon = str_replace('-', ' ', $subfln);
				$titleadon = strtolower ($titleadon);
				$subfln = strtolower ($subfln);
				$titleadon = ucwords ($titleadon);

       

$nextadcompleteurl = 'https://'.$subfln.'.freeadstime.org/'.$urlcorbfl.'/'.$rownext['id'].'/'.$urllinkfl.'';
//echo $nextadcompleteurl;
	   }


   header( "Location: $nextadcompleteurl" ) ;

?>