Seperating Code/Functionality From HTML
Posted: Thu Nov 25, 2004 6:52 am
Hi All
How on earth does one seperate the php from the html. Yet, having the maintenance of the site still being pretty easy.
E.g. Here is some code, how would I perform the current question on it:
How on earth does one seperate the php from the html. Yet, having the maintenance of the site still being pretty easy.
E.g. Here is some code, how would I perform the current question on it:
Code: Select all
<?
require("includes/class.encryption.php");
require("ini.php"); // requires class.encryption.php
require("includes/class.debug.php");
require("includes/class.mysql.php"); // extends class.encryption.php
require("includes/class.utilities.php"); // extends class.mysql.php
require("includes/class.benchmark.php"); // extends class.mysql.php
if ($_SESSIONї"board_pass"] == 1)
{
$skip_check = 1;
require("process.php");
} //if ($_SESSIONї"board_pass"] == 1)
if ($login == 1)
{
if ($timer == 1)
{
$startTimer = $util-> get_formatted_microtime();
} //if ($timer == 1)
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.framesїn.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=dїn])&&d.all) x=d.allїn]; for (i=0;!x&&i<d.forms.length;i++) x=d.formsїi]їn];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layersїi].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=argsїi+2]; val=MM_findObj(argsїi]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<title>Login</title>
<form action="process.php" method="post" name="login" id="login">
<p> </p>
<p> </p>
<p> </p>
<table align="center" class="tableClass">
<tr>
<td rowspan="4"> </td>
<td> </td>
<td> </td>
<td rowspan="4"> </td>
</tr>
<tr>
<td>Login Name </td>
<td><input name="login_name" type="text" class="box" id="login_name"></td>
</tr>
<tr>
<td>Login Password </td>
<td><input name="login_password" type="password" class="box" id="login_password"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" class="submit" onClick="MM_validateForm('login_name','','R','login_password','','R');return document.MM_returnValue" value="Submit"></td>
</tr>
</table>
<p class="info">If you have any problems logging in, please contact us at <? echo $support_email; ?></p>
</form>
<?
if ($timer == 1)
{
$endTimer = $util-> get_formatted_microtime();
if ($startTimer == $endTimer)
{
$totalTime = 0;
} //if ($startTimer == $endTimer)
else
{
$totalTime = $endTimer - $startTimer;
$totalTime = round($totalTime,6);
} //if ($startTimer == $endTimer)
if (strstr($totalTime,"E"))
{
$totalTime = 0;
} //if (strstr($totalTime,"E"))
echo "<p class="info">Execution Time їlogin.php]їlogin screen load]:".$totalTime." second(s)</p>";
$insert_benchmark = $benchmark_site-> insert_benchmark_site("benchmark_site","INTO",NULL,NULL,NULL,NULL,NULL,"now()",0,0,0,0,0,"login.php","login screen load","$totalTime",1,30000,NULL,NULL);
} //if ($timer == 1)
} //if ($login == 1)
?>
<table align="center">
<tr>
<td><img src="images/logos/xampp.jpg"></td>
<td><img src="images/logos/apache.jpg" width="120" height="19"></td>
<td><img src="images/logos/php5.jpg" width="60" height="32"></td>
<td><img src="images/logos/mysql.jpg" width="60" height="31"></td>
</tr>
<tr>
<td colspan="4"><div align="center"><strong class="info">AMP Technology </strong></div></td>
</tr>
</table>