Posts Tagged ‘path setting’


config file having path setting, db setting and file inclusions

Friday, April 18th, 2008

<?php
// start session for login to work
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set(”display_errors”,”On”);
global $winos,$path,$siteurl,$sitepath,$basepath,$module_path;
$winos=0;
if($winos)
{
$path_separator=”\\”;
}
else
{$path_separator=”/”;

}
$path=array();
$basepath=”/var/www/vhosts/tweb.com/subdomains/teamboard/httpdocs”;

///////////  general path cofing and url config ///////////

$path[’path_to_program’] = “http://”.$_SERVER[’HTTP_HOST’];
$path[’fs_path_to_program’] = $basepath;    //the filesystem path to the program www server
$path[”docrootpath”]= $basepath;
$path[”http_url”]= “http://”. $_SERVER[’HTTP_HOST’];
$path[”sitepath”]= “”;  //required if site runs with deeper dir structure from document root
$path[”imagepath”]= $path_separator.”images”;
$path[”includepath”]= “/include”;
$path[”adminpath”]= $path_separator.”admin”; 

while(list($key,$value)=each($path))
{
define($key,$value);
}
$siteurl= $path[http_url] . $path[sitepath];
$sitepath=$path[docrootpath] . $path[sitepath];

//configuring module paths

$module_path=array(”member”=>$path_separator.”member”.$path_separator);

////////////////////////////////////////////////////
/***** Start Database Stuff *****/

global $db_host,$db_user,$db_pass,$db_name,$db_type,$dbobj;

$db_host = “localhost”;//”localhost”;
$db_user = “username”;
$db_pass = “password”;
$db_name = “teamboard”;
$db_type = “mysql”;
$path[’db_prefix’]=”teamboard”;
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”db-master-data.php”);
$dbobj=new dbserver();
$con =  $dbobj->connectdb($db_host, $db_user,$db_pass,$db_name);
/****** End Database Stuff ******/
//load required files//////////////////////////////
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”check_magicquotes.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”db.”.$db_type.”.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”models.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”prepare_data.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”module_operation.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”general_functions.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”login_functions.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”locale_en.php”);
require_once($path[’fs_path_to_program’].$path[”includepath”].$path_separator.”teamboard_functions.php”);

?>


Structured php programming

Friday, April 18th, 2008

It is very important to separate the functionality in separate files. Each file will be responsible to serve the specific meaningful code.

Lets look at the following code of index.php used at http://webwayworld.com/dynamicworld/index.php

1) index.php

<?php
 include “common.php”;   
 
?>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<link href=”<?=HTTP_STYLE.” mainstyle.css”; ?>” rel=”stylesheet” type=”text/css”/>
<title>webwayworld.com</title>
</head>
<body>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
 <tr>
  <td colspan=”2″>
   <? include ROOT_INCLUDE.”header.php”;?>
  </td>
 </tr>
 <tr>
  <td colspan=”2″ align=”right” valign=”middle” class=”website”>
 
   <?
   echo ” Experience the web way world with webwayworld.com”;
   ?>
   
  </td>
 </tr>
 <tr><td colspan=”2″ align=”center”><? echo ” Discover the php solutions “; ?></td></tr>
  <tr>
  <td width=”25%” align=”left” valign=”top”>
  <table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”5″>
  <?php echo “PHP MySQL based <br> web development” ?>
  </table>
 </td>
 
 <td width=”100%” align=”left” valign=”top”>
  <table width=”100%” border=”0″ align=”center” cellspacing=”0″ cellpadding=”5″>
  <?php
  echo “<h1> Explore web way world….<h1>”; ?>
  </table>
 </td>
  </tr>
</table>
</body>
</html>

2) common.php

<?php
 session_start();
 $httphost = $_SERVER[’HTTP_HOST’];
 $docroot = $_SERVER[’DOCUMENT_ROOT’];
 $instal_folder = “/dynamicworld/”;
 
  $rootpath = $docroot.$instal_folder;
 $hostpath = “
http://”.$httphost.$instal_folder;
 
 include $rootpath.”config.php”;
 include ROOT_COMMONDIR.”dbconnect.php”;
 
 include ROOT_FUNCTIONS.”common_functions.php”;
 ?>

3) config.php

<?php
global $rootpath;
global $hostpath;
global $path_separator;
$path_separator = ‘/’;
define(’ROOT_DIR’, $rootpath);
define(’ROOT_INCLUDE’, $rootpath.”includes”.$path_separator);

define(’ROOT_COMMONDIR’, $rootpath.”commondir”.$path_separator);
define(’ROOT_FUNCTIONS’, $rootpath.”functions”.$path_separator);
define(’ROOT_UPLOADS’, $rootpath.”uploads”.$path_separator);
define(’ROOT_STYLE’, $rootpath.”style”.$path_separator);

/*community and eventcalendar module  related root path*/
define(’ROOT_COMMUNITY’, $rootpath.”community”.$path_separator);
define(’ROOT_EVENTCALENDER’, $rootpath.”community/EventCalender”.$path_separator);
define(’ROOT_COMMUNITY_INCLUDE’, ROOT_COMMUNITY.”includes”.$path_separator);

define(’HTTP_DIR’, $hostpath);
define(’HTTP_UPLOADS’, $hostpath.”uploads”.$path_separator);
define(’HTTP_STYLE’, $hostpath.”style”.$path_separator);

/*community and eventcalendar module  related http  url*/
define(’HTTP_COMMUNITY’, $hostpath.”community”.$path_separator);
define(’HTTP_EVENTCALENDER’, $hostpath.”community/EventCalender”.$path_separator);

?>

4)header.php

<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
 <tr>
  <td height=”10″ class=”website”></td>
 </tr>
 <tr>
  <td align=”center” valign=”middle” class=”website”><h1>WAY TO DYNAMIC WEBSITES</h1></td>
 </tr>
 <tr>
  <td align=”center” valign=”middle” class=”website”><h4>WEBWAYWORLD</h4></td>
 </tr>
 <tr>
  <td align=”right” class=”website”>
   <a href=”<?=HTTP_COMMUNITY?>/index.php” mce_href=”<?=HTTP_COMMUNITY?>/index.php”><strong>Social Community</strong></a>
  </td>
 </tr>
</table>