<?php
function SqlInj($iWordName){
		
		$iPageUrl = trim($iWordName);
		$replace = array("'", "]", "'");
		//$replace = '';
		$iMakeLetter= str_replace($replace,"",$iWordName);
		return $iMakeLetter;
}
function token($iTable)
{

	global $db;
	$iLastInsertID	= $db->getVal("select id from  $iTable order by id desc")+1;			
	return rand(1000,9999).$iLastInsertID;
}
function removespace($iWordName)
	{
		$iPageUrl = trim($iWordName);
		$iGetstring = preg_replace("/[^ \w]+/", "", $iPageUrl);
		$replace = array(",","'", "!","@","#","$", "%", "^", "&", "*", "(", ")" , "+" , "=", "â", "’","?","&","+","~"," ");
		$makeurl= str_replace($replace,"-",$iGetstring);
		$iRmoveHypn = array("------","------","-----","-----","-----","----","---","--");
		$blog_url= str_replace($iRmoveHypn,"-",$makeurl);
		$iFinalNameWord = str_replace(array('/\s+/', ' '), '_', trim($blog_url));
		return $iMakeLetter = strtolower($iFinalNameWord);
	}
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
function createbyuser($iUserid)
		{
			global $db;
			$iCreateUserID=$db->getVal("select   create_by from  admin_login where id='".$iUserid."'");	
			return $iCreateUserID;
		}

function redirect($url=NULL)
{
 		echo "<script>window.location='".$url."'</script>";
 		header("Location:".$url);
		echo '<meta http-equiv="refresh" content="1;url='.$url.'" />';
 		exit;
}
function msg($msg)
{
	if(count($msg))
	foreach($msg as $type => $content)
	if($msg[$type]!='')
	{
	 return '<div class="alert alert-'.$type.' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'.$content.'</div>';

	}
} 
function curPageURL() 
{
	$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;
}
function randomnum($length)
{
	$random= "";
	srand((double)microtime()*1000000);
	$data = "1234567890";
	for($i = 0; $i < $length; $i++)
	{
		$random .= substr($data, (rand()%(strlen($data))), 1);
	}
	return $random;
}


?>