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 < so they become harmless. Superglobal Variables Always available in all scopes $GLOBALS References all […]
Category: Memory
Array(13)
References (pointers)(2)
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 […]
Converting Values in PHP
Convert Boolean Text To Boolean Strings always evaluate to boolean true unless they have a value that's considered "empty" by PHP. FILTER_VALIDATE_BOOLEAN provides a solution though: $UploadsEnabled = "false"; $UploadsEnabled = filter_var($UploadsEnabled, FILTER_VALIDATE_BOOLEAN); Convert Bytes To UInt32 $handle = fopen("myfile.bin", "rb"); $Contents = fread($handle, 20); $FileByteArray = unpack("C*",$Contents); //<<<Warning the outputted array starts from [1] […]
Global Variables & Defines
Variables Any variable used inside a function is by default limited to the local function scope. If you want to access a variable used outside of the function you need to declare it as global within the function: Defines No need to declare a define as global in functions, any function can simply use it
Variable Functions
gettype() Returns a string value representing the data type of a variable var_dump() Prints details about the variable it is given
Variables
Variables General Variable names must start with a ‘$’ character (to allow the php parser to work as fast as possible by instantly know it is a variable). A variable name must start with a letter of the alphabet or and underscore ‘_’. Variable names may only contain: ‘a’ – ‘z’, ‘A’ – ‘Z’ and […]