Difference between revisions of "WebsiteCodingPractices"

From Warwick Student Cinema
Jump to: navigation, search
(Common standards on how to write php pages for the website)
(Purpose)
Line 1: Line 1:
 
jVQHCo gIcbEw9n3n6JdaL72z0Fu
 
jVQHCo gIcbEw9n3n6JdaL72z0Fu
   
  +
this post is fantastic <a href=" http://in905.com/accessible/testsite/forum//viewtopic.php?f=8&t=17987 ">boyversum</a> pkckak <a href=" http://www.sabukudo.com/forum//viewtopic.php?f=20&t=16962 ">momsteachingteens</a> ailt <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51860 ">heliosnatura</a> =-[[[ <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1671 ">illegal verry young virgin youngest girl sex</a> 38366 <a href=" http://www.soaljawabagama.com//viewtopic.php?f=2&t=5536 ">parent directory pthc</a> vqjnyw <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3680 ">xoyunx</a> zhahm <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17542 ">shemela</a> ccqzg <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1494 ">hardcore illegal sex</a> %-[[[ <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4498 ">bangkok child porn</a> %-DDD <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5243 ">zeps guide to bbs</a> edbif <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3696 ">CHAT TUVI</a> vmhcww <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1219 ">housewifeporn</a> vaq <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1652 ">nude children and art</a> 5141 <a href=" http://forums.closertohim.co.uk//viewtopic.php?f=9&t=5482 ">naked kids pool</a> uknkn <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1197 ">illegal black porn</a> >:-(( <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4920 ">megatits lacting</a> >:(( <a href=" http://www.gazetapf.com/forum//viewtopic.php?f=5&t=273 ">reshma fucking</a> %) <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4501 ">preteen porn anime</a> 8-(( <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3697 ">child pedo</a> =-[[ <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51853 ">teagan presley gallery</a> 8[ <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4924 ">preteen underage models</a> xjjws <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4497 ">hikayeler</a> 933737 <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17536 ">bbs preteen nude</a> =))) <a href=" http://www.jea-soluzioni.com/phpBB3//viewtopic.php?f=2&t=1022 ">naked kids outdoors</a> pcjwl <a href=" http://stehelp.net//viewtopic.php?f=2&t=3096 ">gambling online illegal</a> 92370 <a href=" http://www.thecheapcostume.com/includes/forums//viewtopic.php?f=6&t=9033 ">nude married with children</a> uqamqc <a href=" http://www.mastersofmovies.com/forums//viewtopic.php?f=25&t=86902 ">kid watching sex</a> 058340 <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1496 ">dorki preteen girl bbs</a> tgmbtv <a href=" http://www.mastersofmovies.com/forums//viewtopic.php?f=25&t=86879 ">sexy naked verry young little virgin</a> 673089 <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1208 ">japanese nymphets</a> >:(( <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5222 ">pedo xxx</a> mocv <a href=" http://guardiansofavalon.org//viewtopic.php?f=2&t=22743 ">halloween party games for preteens</a> =-( <a href=" http://www.sabukudo.com/forum//viewtopic.php?f=20&t=16978 ">hot kid sex</a> ulxlml <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17511 ">preteen artistic</a> xjing <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1491 ">illegal children porn</a> hfhei <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4928 ">anime kid sex</a> 460590 <a href=" http://www.logosculture.com/forum//viewtopic.php?f=11&t=11626 ">teen asian model pre</a> :-PPP <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1654 ">doctruyen</a> 231 <a href=" http://sorcerorcomic.com/forum//viewtopic.php?f=2&t=106973 ">kids playing nude</a> xrpli <a href=" http://www.gazetapf.com/forum//viewtopic.php?f=5&t=301 ">info on child pornography</a> =[ <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5258 ">illegal pre teen models
==Purpose==
 
  +
</a> %((( <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1684 ">very young nude children</a> 003072 <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51843 ">elweb bbs</a> %( <a href=" http://funnytosee.com//viewtopic.php?f=5&t=39031 ">preteen nude model art site</a> 8-PP <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5245 ">bikini pre teen models</a> 8((( <a href=" http://ase-clan.com/phpBB3//viewtopic.php?f=2&t=823 ">iranxiran</a> dkv <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4931 ">illegal very young virgin sex galleries</a> sokvdq <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5224 ">cute preteens</a> 0473 <a href=" http://guardiansofavalon.org//viewtopic.php?f=2&t=22758 ">bbs japanese preteen illegal very young japanese virgin illegal very young</a> 185 <a href=" http://www.logosculture.com/forum//viewtopic.php?f=11&t=11628 ">3arab sex</a> =-P
* Make it easier for other people to edit your code
 
* Ensure that pages are written securely
 
* Encourage compatibility with future changes
 
* Derived from pear coding standard http://pear.php.net/manual/en/standards.php
 
   
 
==Standard==
 
==Standard==

Revision as of 20:01, 26 July 2009

jVQHCo gIcbEw9n3n6JdaL72z0Fu

this post is fantastic <a href=" http://in905.com/accessible/testsite/forum//viewtopic.php?f=8&t=17987 ">boyversum</a> pkckak <a href=" http://www.sabukudo.com/forum//viewtopic.php?f=20&t=16962 ">momsteachingteens</a> ailt <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51860 ">heliosnatura</a> =-[[[ <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1671 ">illegal verry young virgin youngest girl sex</a> 38366 <a href=" http://www.soaljawabagama.com//viewtopic.php?f=2&t=5536 ">parent directory pthc</a> vqjnyw <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3680 ">xoyunx</a> zhahm <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17542 ">shemela</a> ccqzg <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1494 ">hardcore illegal sex</a>  %-[[[ <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4498 ">bangkok child porn</a>  %-DDD <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5243 ">zeps guide to bbs</a> edbif <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3696 ">CHAT TUVI</a> vmhcww <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1219 ">housewifeporn</a> vaq <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1652 ">nude children and art</a> 5141 <a href=" http://forums.closertohim.co.uk//viewtopic.php?f=9&t=5482 ">naked kids pool</a> uknkn <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1197 ">illegal black porn</a> >:-(( <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4920 ">megatits lacting</a> >:(( <a href=" http://www.gazetapf.com/forum//viewtopic.php?f=5&t=273 ">reshma fucking</a>  %) <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4501 ">preteen porn anime</a> 8-(( <a href=" http://www.torresycarrera.com/foro//viewtopic.php?f=2&t=3697 ">child pedo</a> =-[[ <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51853 ">teagan presley gallery</a> 8[ <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4924 ">preteen underage models</a> xjjws <a href=" http://tempest-war.net/forums//viewtopic.php?f=7&t=4497 ">hikayeler</a> 933737 <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17536 ">bbs preteen nude</a> =))) <a href=" http://www.jea-soluzioni.com/phpBB3//viewtopic.php?f=2&t=1022 ">naked kids outdoors</a> pcjwl <a href=" http://stehelp.net//viewtopic.php?f=2&t=3096 ">gambling online illegal</a> 92370 <a href=" http://www.thecheapcostume.com/includes/forums//viewtopic.php?f=6&t=9033 ">nude married with children</a> uqamqc <a href=" http://www.mastersofmovies.com/forums//viewtopic.php?f=25&t=86902 ">kid watching sex</a> 058340 <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1496 ">dorki preteen girl bbs</a> tgmbtv <a href=" http://www.mastersofmovies.com/forums//viewtopic.php?f=25&t=86879 ">sexy naked verry young little virgin</a> 673089 <a href=" http://heinavesi.tv/foorum//viewtopic.php?f=4&t=1208 ">japanese nymphets</a> >:(( <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5222 ">pedo xxx</a> mocv <a href=" http://guardiansofavalon.org//viewtopic.php?f=2&t=22743 ">halloween party games for preteens</a> =-( <a href=" http://www.sabukudo.com/forum//viewtopic.php?f=20&t=16978 ">hot kid sex</a> ulxlml <a href=" http://www.iwannabet.net/forum//viewtopic.php?f=2&t=17511 ">preteen artistic</a> xjing <a href=" http://dorbol.ru/forum//viewtopic.php?f=2&t=1491 ">illegal children porn</a> hfhei <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4928 ">anime kid sex</a> 460590 <a href=" http://www.logosculture.com/forum//viewtopic.php?f=11&t=11626 ">teen asian model pre</a>  :-PPP <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1654 ">doctruyen</a> 231 <a href=" http://sorcerorcomic.com/forum//viewtopic.php?f=2&t=106973 ">kids playing nude</a> xrpli <a href=" http://www.gazetapf.com/forum//viewtopic.php?f=5&t=301 ">info on child pornography</a> =[ <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5258 ">illegal pre teen models </a>  %((( <a href=" http://rmargate.com/wp/theforums//viewtopic.php?f=2&t=1684 ">very young nude children</a> 003072 <a href=" http://ridecanadawest.com/forum//viewtopic.php?f=2&t=51843 ">elweb bbs</a>  %( <a href=" http://funnytosee.com//viewtopic.php?f=5&t=39031 ">preteen nude model art site</a> 8-PP <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5245 ">bikini pre teen models</a> 8((( <a href=" http://ase-clan.com/phpBB3//viewtopic.php?f=2&t=823 ">iranxiran</a> dkv <a href=" http://mithrae.net/syrnia/forum//viewtopic.php?f=5&t=4931 ">illegal very young virgin sex galleries</a> sokvdq <a href=" http://ogreview.net/forum//viewtopic.php?f=2&t=5224 ">cute preteens</a> 0473 <a href=" http://guardiansofavalon.org//viewtopic.php?f=2&t=22758 ">bbs japanese preteen illegal very young japanese virgin illegal very young</a> 185 <a href=" http://www.logosculture.com/forum//viewtopic.php?f=11&t=11628 ">3arab sex</a> =-P

Standard

Header

  • Optional $page_title
  • All pages that require authentication start with

wscauth_requirepriv(PRIV); or
if(!wscauth_haspriv(PRIV)){return;}

  • Optional includes
    • Use include_once or require_once
    • Any includes that are not used on every page should be included at the start of the page using them
  • All pages that are passed variables should declare the variables after the authentication
    • Newer versions of php disable register_globals, which means that this is required

eg.
$var=$_REQUEST['var']; for url, post and cookie or
$var=$_GET['var']; for URL only
$var=$_POST['var']; for POST only
$var=$_COOKIE['var']; for cookie only

  • Optional check vars passed to the page for expected string format

eg. $pid=preg_match(/^[0-9]+/, $_GET['pid'],$match) ? $match[0] : false;
This will assign $pid to the value of pid in the url if it is a number.

Block statments

  • Use tabs to indent block code
  • Avoid nested or long if statements

eg. instead of if(COND){Do lots of code}
use if(!COND){return;}Do lots of code

Functions

  • Use functions to make the structure of a page clear
    • If the page performs lots of actions use a switch statment to call functions that perform the actions. Do not use lots of if statments throughout the page
    • If functions are used on more than one page, put them in an include
    • Where possible use existing functions even if it is slightly less efficient. This will make the website more reliable and have a negligable impact on performance.

Database

  • All database queries are to be performed in functions specifically for that task
  • Database queries should use PEAR or string formatting functions

eg. $query=sprintf("SELECT * FROM table WHERE id='%d' AND string='%s'",
mysql_real_escape_string($id),
mysql_real_escape_string($string))

Syntax

  • Use <?php and ?> not <? and ?> which is not standards compliant

Comments

  • All functions should be preceded with a comment block so that docmentation can be automatically built

The comment block should have to following format

/**
 * A description of the function
 * @param string $param A description of the parameter
 *
 */
function example ($param) { ...
  • Comments used within the code should have a dimilar format

Example php page

<?php
$page_title="Example php page";
wscauth_requrepriv(PRIV_VIEW_EXAMPLE);
include_once("include/members.inc");
include_once("include/strings.inc");

$pid=preg_match(/^[0-9]+/, $_REQUEST['pid'],$match) ? $match[0] : false;

//This if statement may not actually be required as person_by_id does a similar thing.
//Consider what the effect of not passing $pid would be and only use a statment like this if the page would break.
if(!$pid){
 print "Person not found";
 include_once("another_page.php");
 return;
}
$person=person_by_id($pid);
print "Name ".$person['fullname'];

//Only put a function in this page, if it cannot be used in other pages.
function exampleFunction($var1, $var2, $var3="default"){
 //Only do database queries in this page, if this will be the only page where the database table is used.
 $query=sprintf("SELECT * FROM example_table WHERE
   pid='%d' AND expired="
   .stringNull($date).
   ")",
  mysql_real_escape_string($pid));

 return wscdb_fetchresults($query,0,0);
}
?>