Posts Tagged ‘cofing file’


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>