post-module php forms btm 395: internet programming
TRANSCRIPT
![Page 1: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/1.jpg)
Post-Module PHP Forms
BTM 395: Internet Programming
![Page 2: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/2.jpg)
Cookies• Cookie is a name-value pair stored on the
user’s (client) computer– Track preferences and other information
• Each server’s cookies stored as a text file on client computer– Stored securely so that it is difficult for other server-
side applications to access another’s cookies– But don’t store sensitive information (e.g. credit card
number) without encryption• Security risk if someone has physical access to the user’s
computer
• Write or change cookies:– setcookie( $name, $value ); various optional options
(e.g. expiration date)• Read cookies
– Use the $_COOKIE['name'] environment variable
![Page 3: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/3.jpg)
Sessions
• A session is a built-in way of tracking a user across multiple pages
• Implemented using cookies• Thus, requires cookies to be enabled on client
side
![Page 4: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/4.jpg)
PHP string quoting• ' (single quote): for literal strings with minimal
text expansion (\\ and \' only)
• " (double quote): for flexible strings with expansion of variables and many codes (e.g. \n and \t)
• Heredoc: for lengthy strings with complex plain-text format (see http://codepad.org/pzHHK3wH) – Begins with <<<ANY_DELIMITER– Ends with ANY_DELIMITER; as the only contents of
closing line– Expands variables similarly to "– Nowdoc format works like single quote equivalent of
heredoc• Official reference: http://
php.net/manual/en/language.types.string.php
![Page 5: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/5.jpg)
Array indexing
• ALL arrays in PHP are associative arrays• Numeric indices are automatically
generated, but the arrays are still fully associative
• Arrays can have both flexible associative keys and auto-generated numeric keys
• Official reference: http://www.php.net/manual/en/language.types.array.php
![Page 6: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/6.jpg)
Customized array sorting
• PHP has many built in array sort functions, for sorting by value, by key, and backwards
• JavaScript only has one very limited built-in sort: lexicographic (strict alphabetic) sort
• Both have custom sort functions that work similarly– JavaScript: myArray.sort(function(a,b){…});– PHP: usort($myArray,customSortFunction);
customSortFunction(a,b){…};– These can sort any kind of array anyway
you like, including multidimensional arrays
![Page 7: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/7.jpg)
Other PHP tips
• Equality and assignment= vs == vs ===
• The ternary (conditional) operator ? :– $myVar = $testCondition ? $valueIfTrue :
$valueIfFalse;– Ternary operator exercise
• Stop an infinite loop in PHP– Click the stop or cancel button on your browser to
stop the page loading– Or just wait 30 seconds or so for a server timeout
![Page 8: Post-Module PHP Forms BTM 395: Internet Programming](https://reader036.vdocument.in/reader036/viewer/2022082710/56649e155503460f94aff2f7/html5/thumbnails/8.jpg)
Sources
• Heredoc example: http://www.tuxradar.com/practicalphp/2/6/3