Using Strings-Verifying Strings

Is String Numeric Is String A Date Time Is String Within An Array Of Strings Check Entered Web Address This isn’t right – the first test rejects doamins with a hyphen in them Verify Email Address A thorough version from this article here  

Read More

Differences To C and C++

=== and !=== PHP is a loosly typed language.  For instance this is true because PHP converts to the requried types before the compare: if (1000 == “+1000”) To perform an exact comparison you can use this instead, which is false if (1000 === “+1000”) For does not equal you can also use !== Break […]

Read More

Convert Strings

Converting to HTML, from form POST, etc See here Converting String To Variable You don’t need to, but if you want to force to a particular type you can: Converting Variables To String No need, PHP automatically converts a varaible to the type needed for the context being used Convert copy and pasted text Remove […]

Read More

Sanitising & encoding strings

Sanitising for HTML Convert special HTML entities back to characters Sanitising for HTML from a form POST See page here. filter_var() function Returns the input string filtered, or FALSE if it was unable to perform the sanitization (e.g. due to an illegal character) See here for all the available filter options See here for examples […]

Read More

Built In Superglobal Variables

Warning When Using Superglobal Variables Hackers often use these to try and inject code etc.  When accessing superglobal variables ensure you sanitise them.  E.g. $CameFromPage = htmlentities($_SERVER[‘HTTP_REFERER’]); //htmlentities() converts things like < > ” \ etc into HTML strings like &lt; so they become harmless. Superglobal Variables Always available in all scopes $GLOBALS References all […]

Read More

Print vs Echo

Print is a PHP function called with an argument.  Echo is a PHP language construct.  Echo is therefore faster, but when you need an actual function call you can use print.  For example this only wotks using print: $MyVariable ? print “True” : print “False”;

Read More

Constants

Constants define (“MY_ROOT_PATH”, “/usr/local/httpdocs/”); Then to use $PathToUse = MY_ROOT_PATH; PHP Magic Constants __LINE__ The current line number of the file. __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved […]

Read More