what is this common.php it is located in includes folder where the class files are located.I dont understand please help me i am new to php and it contains the following coading in it.Why we use it?

<?php 
ob_start();

	session_start();
	 //$_SERVER['DOCUMENT_ROOT'] = "/home/gt5com/public_html";
	
	if(!defined("_MAINSITEPATH_"))

		define("_MAINSITEPATH_",$_SERVER['DOCUMENT_ROOT']."/talent6/includes/");

	if(!defined("EMAIL_LINEFEED"))

		define("EMAIL_LINEFEED",'CRLF');

	if(!defined("EMAIL_TRANSPORT"))

		define("EMAIL_TRANSPORT",'mime');

	if(!defined("CHARSET"))

		define("CHARSET",'iso-8859-1');

		define('PREVNEXT_BUTTON_PREV', '<b>&lt;&lt;</b>');

	define('PREVNEXT_BUTTON_NEXT', '<b>&gt;&gt;</b>');

	define('TEXT_DISPLAY_NUMBER_OF_INVITES', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> Invites)');

	define('TEXT_DISPLAY_NUMBER_OF_INBOX', 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> Mails)');

	define('TEXT_DISPLAY_NUMBER_OF_FIND', 'Search Result  <b>%d</b> to <b>%d</b> (of <b>%d</b> Matches)');

	define('TEXT_DISPLAY_NUMBER_OF_UPEVENTS', 'UpComing  <b>%d</b> to <b>%d</b> (of <b>%d</b> Events)');

	define('TEXT_DISPLAY_NUMBER_OF_PASTEVENTS', 'Past  <b>%d</b> to <b>%d</b> (of <b>%d</b> Events)');

	define('TEXT_DISPLAY_NUMBER_OF_COMMENTS', 'Displaying  <b>%d</b> to <b>%d</b> Comment(s)');

	define('TEXT_DISPLAY_NUMBER_OF_FAVORITES', 'Listing  <b>%d</b> to <b>%d</b> Favorites(s)');	

	define('TEXT_DISPLAY_NUMBER_OF_ADDRESS', 'Listing  <b>%d</b> to <b>%d</b> Address(s)');	

	define('TEXT_RESULT_PAGE', 'Page %s of %d');

	define('TEXT_DISPLAY_NUMBER_OF_RESULT', '<b>%d</b> to <b>%d</b> (of <b>%d</b>)');

	define('TEXT_RESULT_PAGE', 'Page %s of %d');

	define('TEXT_RESULT_PAGE1', 'Result Pages:');

	define('PREVNEXT_TITLE_FIRST_PAGE', 'First Page');

	define('PREVNEXT_TITLE_PREVIOUS_PAGE', 'Previous Page');

	define('PREVNEXT_TITLE_NEXT_PAGE', 'Next Page');

	define('PREVNEXT_TITLE_LAST_PAGE', 'Last Page');

	define('PREVNEXT_TITLE_PAGE_NO', 'Page %d');

	define('PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE', 'Previous Set of %d Pages');

	define('PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE', 'Next Set of %d Pages');

	define('PREVNEXT_BUTTON_FIRST', '&lt;&lt;FIRST');

	define('PREVNEXT_BUTTON_PREV1', '[&lt;&lt;&nbsp;Prev]');

	define('PREVNEXT_BUTTON_NEXT1', '[Next&nbsp;&gt;&gt;]');

	define('PREVNEXT_BUTTON_LAST', 'LAST&gt;&gt;');

	

	

	include_once _MAINSITEPATH_."config.php";

	include_once _MAINSITEPATH_."dbNames.php";

	include_once $config['SiteClassPath']."class.SqlFunctions.php";

	include_once $config['SiteClassPath']."class.General.php";

	include_once $config['SiteClassPath']."class.Mime.php";

	include_once $config['SiteLocalPath']."includes/smarty/Smarty.class.php";

	include_once _MAINSITEPATH_."EmailNotificationSend.php";

	include_once _MAINSITEPATH_."libmail.php";

	//include_once $config['SiteClassPath']."class.Upload.php";

	//include_once $config['SiteClassPath']."class.General.php";	

	global $config;

	

	$objSmarty	= new Smarty();

	if(isset($_SESSION))

		$objSmarty->assign("Session", $_SESSION);

		

		if(!empty($_SESSION['member_id']))

	{

			$objSmarty->assign("member_id",$_SESSION['member_id']);

	}

	/*Magic Function for Load All Class Files Start 

	  function __autoload($class_name) 

	  {

	   require_once $config['SiteClassPath']."class.".trim($class_name).'.php';

	   	  }*/

	 /*Magic Function for Load All Class Files End */

	function getWebSettings()

	{

		global $objSmarty;

		$objMysqlFns	= new MysqlFns();

		$Query			= "select * from ".Tmy_Websettings." Limit 0,1";

		$Result			= $objMysqlFns->ExecuteQuery($Query, "select");

		$objSmarty->assign("WebSettings", $Result[0]);

		return $Result[0];

	}

	    $objMysqlFns	= new MysqlFns();

		//////////////////////////////////////////////////////////////////////////////SESSION MEMBER ID

		 $SqlSelectstaticpages    = "select * from tbl_contentpages where Con_Status=1";

		 $staticpages_array       = $objMysqlFns->ExecuteQuery($SqlSelectstaticpages,"select");

		 $objSmarty->assign("con_pages",$staticpages_array);

		 

	function NavigationLink($NavigationLinks)

	{

		global $objSmarty, $config;

		$Navigation	= " <a href='".$config['SiteGlobalPath']."'  class='Navigation'> Home </a>";

		if(!empty($NavigationLinks) && is_array($NavigationLinks))

			foreach($NavigationLinks as $key=>$value)

			{

				$Navigation .= " >> ". " <a href='".$NavigationLinks[$key]['Link']."'  class='Navigation'> ".$NavigationLinks[$key]['Title']." </a>";

			}

			

		$objSmarty->assign("NavigationLinks", $Navigation);

	}

	

	function printArray($Array)

	{

		print "<Pre>";

		print_r($Array);

		print "</Pre>";

	}

	

	function Redirect($Url)

	{

		header("Location:".$Url);

		exit;

	}

	

	function PrePopulate($objArray, $ArrayName='')

	{

		global $objSmarty;

		if(!empty($objArray) && is_array($objArray))

		{

			if(!empty($ArrayName))

			{	

				$Array = array();

				foreach($objArray as $key=>$value)

					$Array[$key] = $value;

				$$ArrayName	= $Array;

				$objSmarty->assign($ArrayName,$$ArrayName);

			}

			else

				foreach($objArray as $key=>$value)

					$objSmarty->assign($key,$value);

		}

	}

	/*Drop Down Menu Start */

	function draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {

    $field = '<select name="' . output_string($name) . '"';



    if (not_null($parameters)) $field .= ' ' . $parameters;



    $field .= '>';



    if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);



    for ($i=0, $n=sizeof($values); $i<$n; $i++) {

      $field .= '<option value="' . output_string($values[$i]['id']) . '"';

      if ($default == $values[$i]['id']) {

        $field .= ' SELECTED';

      }



      $field .= '>' . output_string($values[$i]['text'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '</option>';

    }

    $field .= '</select>';



    if ($required == true) $field .= 'Field Is Required';



    return $field;

  }

   function not_null($value) {

    if (is_array($value)) {

      if (sizeof($value) > 0) {

        return true;

      } else {

        return false;

      }

    } else {

      if ( (is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) {

        return true;

      } else {

        return false;

      }

    }

  }

function output_string($string, $translate = false, $protected = false) {

    if ($protected == true) {

      return htmlspecialchars($string);

    } else {

      if ($translate == false) {

        return parse_input_field_data($string, array('"' => '&quot;'));

      } else {

        return parse_input_field_data($string, $translate);

      }

    }

  }

  ////

// Parse the data used in the html tags to ensure the tags will not break

  function parse_input_field_data($data, $parse) {

    return strtr(trim($data), $parse);

  }

  

  function convert_linefeeds($from, $to, $string) 

		{

			if ((PHP_VERSION < "4.0.5") && is_array($from)) 

			{

			return ereg_replace('(' . implode('|', $from) . ')', $to, $string);

			} 

			else 

			{

			return str_replace($from, $to, $string);

			}

		}

		

		function draw_form($name, $action, $parameters = '', $method = 'post', $params = '') 

{

	$form = '<form name="' . output_string($name) . '" action="';

		if (not_null($parameters)) 

		{

		$form .= href_link($action, $parameters);

		} 

		else 

		{

		$form .= href_link($action);

		}

		$form .= '" method="' . output_string($method) . '"';

		if (not_null($params)) 

		{

		$form .= ' ' . $params;

		}

		$form .= '>';

	

	return $form;

}



function href_link($page = '', $parameters = '', $connection = 'NONSSL') 

  {

    /*if ($page == '') {

      die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>Function used:<br><br>href_link(\'' . $page . '\', \'' . $parameters . '\', \'' . $connection . '\')</b>');

    }

    if ($connection == 'NONSSL') 

	{

     // $link = HTTP_SERVER . DIR_WS_ADMIN;

	 $link = $config['SiteGlobalPath'];

    }

	else 

	{

      die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL<br><br>Function used:<br><br>tep_href_link(\'' . $page . '\', \'' . $parameters . '\', \'' . $connection . '\')</b>');

    }*/

    if ($parameters == '') {

      $link = $link . $page . '?' . SID;

    } else {

      $link = $link . $page . '?' . $parameters . '&' . SID;

    }



    while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);



    return $link;

  }

   function draw_hidden_field($name, $value = '', $parameters = '') {

    $field = '<input type="hidden" name="' . output_string($name) . '"';



    if (not_null($value)) {

      $field .= ' value="' . output_string($value) . '"';

    } elseif (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) {

      $field .= ' value="' . output_string(stripslashes($GLOBALS[$name])) . '"';

    }



    if (not_null($parameters)) $field .= ' ' . $parameters;



    $field .= '>';



    return $field;

  }

	



  

   function db_error($query, $errno, $error) { 

    die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[MySql Error]</font></small><br><br></b></font>');

  }



  /*Drop Down Menu End */

  

   function get_all_get_params($exclude_array = '') {

    global $HTTP_GET_VARS;



    if (!is_array($exclude_array)) $exclude_array = array();



    $get_url = '';

    if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {

      reset($HTTP_GET_VARS);

      while (list($key, $value) = each($HTTP_GET_VARS)) {

        if ( (strlen($value) > 0) && ($key != temp_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {

          $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';

        }

      }

    }

	//print_r($get_url);

    return $get_url;

  }

   function temp_session_name($name = '') {

if(!empty($name)) 
  {
 return session_name($name);
  } 
 else 
  {
 return session_name();
  }
}

function db_input($string) 
{
 global $$link;
 if (function_exists('mysql_real_escape_string')) 
 {return mysql_real_escape_string($string);}elseif (function_exists('mysql_escape_string')) {
 return mysql_escape_string($string);
 }
 return addslashes($string);
 }
 foreach($config as $key=>$value)
 $objSmarty->assign("gl_".$key,$value);
?>

this is comman file, which will be included in your all php files.So you dont have to write this files code in all files.

Member Avatar for diafol

It looks like a sort of configuration file for all pages. It just gives constants and useful functions required by all pages.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.