cvs: presentations /slides/advanced advancedphp.jpg apd.jpg arraybench.php bb-small.jpg bb.jpg ccache.jpg cookie.php d_knowledge1.xml e_logging.xml
e_logging1.xml e_recieving.xml e_recieving1.xml e_recieving2.xml e_recieving3.xml e_shielding.xml encryptsensitive.php errorhandler.php errors.sqlite
inject.php ninja.gif p_apd.xml p_apd1.xml p_apd2.xml p_apd3.xml p_benchmark.xml p_benchmark1.xml p_benchmark2.xml p_cacheability.xml p_ccache.xml
p_ccache1.xml p_ccache2.xml p_gzip.xml p_io.xml p_perf.xml p_profiling.xml p_squid.xml p_truisms.xml pres2.output request.jpg s_arch.xml s_encrypt.xml
s_encrypt1.xml s_encrypt2.xml s_injection.xml s_injection1.xml s_security.xml s_security1.xml s_validation.xml s_validation1.xml sencrypt.pl
simpleexcept.php squid1.png thanks.xml
| From: | Sterling Hughes | Date: | Mon, 07 Jul 2003 22:05:47 +0000 |
| Subject: | cvs: presentations /slides/advanced advancedphp.jpg apd.jpg arraybench.php bb-small.jpg bb.jpg ccache.jpg cookie.php d_knowledge1.xml e_logging.xml e_logging1.xml e_recieving.xml e_recieving1.xml e_recieving2.xml e_recieving3.xml e_shielding.xml encryptsensitive.php errorhandler.php errors.sqlite inject.php ninja.gif p_apd.xml p_apd1.xml p_apd2.xml p_apd3.xml p_benchmark.xml p_benchmark1.xml p_benchmark2.xml p_cacheability.xml p_ccache.xml p_ccache1.xml p_ccache2.xml p_gzip.xml p_io.xml p_perf.xml p_profiling.xml p_squid.xml p_truisms.xml pres2.output request.jpg s_arch.xml s_encrypt.xml s_encrypt1.xml s_encrypt2.xml s_injection.xml s_injection1.xml s_security.xml s_security1.xml s_validation.xml s_validation1.xml sencrypt.pl simpleexcept.php squid1.png thanks.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-800@lists.php.net to get a copy of this message | ||
sterling Mon Jul 7 18:05:47 2003 EDT
Added files:
/presentations/slides/advanced advancedphp.jpg apd.jpg
arraybench.php bb-small.jpg bb.jpg
ccache.jpg cookie.php e_logging.xml
e_logging1.xml e_recieving1.xml
e_recieving2.xml e_recieving3.xml
e_shielding.xml encryptsensitive.php
errorhandler.php errors.sqlite
inject.php ninja.gif p_apd.xml
p_apd1.xml p_apd2.xml p_apd3.xml
p_benchmark.xml p_benchmark1.xml
p_benchmark2.xml p_cacheability.xml
p_ccache.xml p_ccache1.xml
p_ccache2.xml p_gzip.xml p_io.xml
p_perf.xml p_profiling.xml
p_squid.xml p_truisms.xml
pres2.output request.jpg s_arch.xml
s_encrypt.xml s_encrypt1.xml
s_encrypt2.xml s_injection.xml
s_injection1.xml s_security.xml
s_security1.xml s_validation.xml
s_validation1.xml sencrypt.pl
simpleexcept.php squid1.png
thanks.xml
Modified files:
/presentations/slides/advanced d_knowledge1.xml e_recieving.xml
Log:
more advanced php slides
Index: presentations/slides/advanced/d_knowledge1.xml diff -u presentations/slides/advanced/d_knowledge1.xml:1.2 presentations/slides/advanced/d_knowledge1.xml:1.3 --- presentations/slides/advanced/d_knowledge1.xml:1.2 Sun Jul 6 19:12:24 2003 +++ presentations/slides/advanced/d_knowledge1.xml Mon Jul 7 18:05:47 2003 @@ -7,6 +7,7 @@ <bullet>Wikis (coWiki, phpWiki)</bullet> <bullet>CVS</bullet> <bullet>CVSTrac (http://www.cvstrac.org/)</bullet> +<bullet>FIT (http://fit.c2.com/ - See the presentation this week)</bullet> </list> </slide> Index: presentations/slides/advanced/e_recieving.xml diff -u presentations/slides/advanced/e_recieving.xml:1.1 presentations/slides/advanced/e_recieving.xml:1.2 --- presentations/slides/advanced/e_recieving.xml:1.1 Sun Jul 6 19:12:24 2003 +++ presentations/slides/advanced/e_recieving.xml Mon Jul 7 18:05:47 2003 @@ -1,5 +1,27 @@ <slide title="Recieving"> -<blurb> +<break/> +<image filename="stonehenge.jpg" align="right" marginright="1.0em"/> +<blurb fontsize="4.0em"> +The classic manner of PHP error handling is to use lots and lots of +%if%'s. </blurb> +<example><![CDATA[<?php +$conn = mysql_connect('localhost', 'user', 'pass'); +if (!$conn) { + die("bah bah bear"); +} +if (!mysql_select_db('bing', $conn)) { + die("booh hoo hoo"); +} + +$stmt = mysql_query('select * baz from bar', $conn); +if (!$stmt) { + die("wah wah woo"); +} + +if (!mysql_num_rows($conn)) { + die("ding dong doo"); +} +?>]]></example> </slide> Index: presentations/slides/advanced/arraybench.php +++ presentations/slides/advanced/arraybench.php <?php require_once "Benchmark/Iterate.php"; $test_array = create_random_array(100); foreach(array('max', 'my_max') as $func) { $b = new Benchmark_Iterate; $b->run('10000', $func, $test_array); $result = $b->get(); print "$func\t"; printf("System + User Time: %1.6f\n", $result['mean']); } function create_random_array($size) { $array = array(); for($i=0; $i < $size; $i++) { $array[$i] = rand(); } return $array; } function my_max($array) { reset($array); $max = current($array); while( $el = next($array)) { if($el > $max) { $max = $el; } } return $max; } ?> Index: presentations/slides/advanced/cookie.php +++ presentations/slides/advanced/cookie.php <?php if (isset($_COOKIE['stamp'])) { if ($_COOKIE['stamp'] == md5($_COOKIE['data'] . 'SECRETKEY')) { echo "valid cookie\n"; } else { echo "tamper temper"; } } else { $_COOKIE['data'] = '00110100011'; $_COOKIE['stamp'] = md5($_COOKIE['data'] . 'SECRETKEY'); } ?> Index: presentations/slides/advanced/e_logging.xml +++ presentations/slides/advanced/e_logging.xml <slide title="Logging"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> Logging must be designed for extensibility </blurb> <blurb fontsize="4.0em"> When your application grows, logging can quickly become a bottleneck </blurb> <blurb fontsize="4.0em"> Use apache's logging facilities, extend with a custom module, eg, spread. </blurb> </slide> Index: presentations/slides/advanced/e_logging1.xml +++ presentations/slides/advanced/e_logging1.xml <slide title="The Humanity!"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> *Do Not* email yourself the logs for every failed message. Write high priority failures to a log file, and then email yourself that logfile (or the location of that logfile). </blurb> <blurb fontsize="4.0em"> If you are SMS' yourself failed error logs, you should consider investing in a second system administrator </blurb> <blurb fontsize="4.0em"> Make logs into test cases! </blurb> </slide> Index: presentations/slides/advanced/e_recieving1.xml +++ presentations/slides/advanced/e_recieving1.xml <slide title="Pull Error Handling"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <blurb fontsize="4.0em">%set_error_handler()% and %trigger_error()% are good tools for logging error messages</blurb> <blurb fontsize="4.0em">They *are not* a substitute for proper flow control statements</blurb> <example filename="errorhandler.php"/> </slide> Index: presentations/slides/advanced/e_recieving2.xml +++ presentations/slides/advanced/e_recieving2.xml <slide title="Exceptions"> <break/> <image filename="stonehenge.jpg" align="right" marginright="right"/> <break lines="5" /> <blurb fontsize="4.0em">Exceptions allow you to catch errors and change your flow control</blurb> <blurb fontsize="4.0em">They are incredibly useful when it comes to error handling</blurb> <blurb fontsize="4.0em">They are PHP *5* only</blurb> </slide> Index: presentations/slides/advanced/e_recieving3.xml +++ presentations/slides/advanced/e_recieving3.xml <slide title="Exception Example"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="6"/> <example filename="simpleexcept.php" /> </slide> Index: presentations/slides/advanced/e_shielding.xml +++ presentations/slides/advanced/e_shielding.xml <slide title="Shielding"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> Set %display_errors = Off% </blurb> <blurb fontsize="4.0em"> Use a custom error handler </blurb> <blurb fontsize="4.0em"> Log all error levels to different locations </blurb> </slide> Index: presentations/slides/advanced/encryptsensitive.php +++ presentations/slides/advanced/encryptsensitive.php <?php $key = 'Welcome to the monkey house' $s = 'cc-number-goes-here'; $alg = MCRYPT_BLOWFISH; $mode = MCRYPT_MODE_CBC; $iv = mcrypt_create_iv( mcrypt_get_iv_size($alg, $mode), MCRYPT_DEV_URANDOM ); $data = mcrypt_encrypt($alg, $key, $s, $mode, $iv); mysql_query( sprintf("INSERT INTO customers (iv, data) ('%s', '%s')", mysql_escape_string($iv), mysql_escape_string($data) ), $dbh ); ?> Index: presentations/slides/advanced/errorhandler.php +++ presentations/slides/advanced/errorhandler.php <?php function log_error_sqlite($errno, $errstr, $errfile, $errline) { global $edbh; if (!$edbh) { $edbh = sqlite_open("errors.sqlite"); sqlite_query( 'create table errors ( errno, errstr, errfile, errline )', $edbh); } sqlite_query(sprintf("insert into errors values ('%s', '%s', '%s', '%s')", sqlite_escape_string($errno), sqlite_escape_string($errstr), sqlite_escape_string($errfile), sqlite_escape_string($errline)), $edbh); } set_error_handler('log_error_sqlite'); $result = 1 / 0; ?> Index: presentations/slides/advanced/errors.sqlite +++ presentations/slides/advanced/errors.sqlite ** This file contains an SQLite 2.1 database ** (uãÚ Ð e etable errors errors 3 create table errors ( errno, errstr, errfile, errline ) " à t Z WZ2 Division by zero /data/www/pres2/presentations/slides/advanced/errorhandler.php 25 Z WZ2 Division by zero /data/www/pres2/presentations/slides/advanced/errorhandler.php 25 Index: presentations/slides/advanced/inject.php +++ presentations/slides/advanced/inject.php <?php $dir = $_GET['directory']; $contents = `ls $dir`; echo $contents; ?> Index: presentations/slides/advanced/p_apd.xml +++ presentations/slides/advanced/p_apd.xml <slide title="APD"> <break/> <image filename="ninja.gif" align="right"/> <image filename="apd.jpg" align="left"/> <break lines="10"/> <blurb fontsize="4.0em">Intercepts calls to %zend_execute%</blurb> <blurb fontsize="4.0em">Generates function call traces with timings</blurb> </slide> Index: presentations/slides/advanced/p_apd1.xml +++ presentations/slides/advanced/p_apd1.xml <slide title="Installing APD"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> Install APD via PEAR </blurb> <example type="shell"><![CDATA[# pear install apd % mkdir /tmp/traces]]></example> <blurb fontsize="4.0em"> Then add the following to your %php.ini% file: </blurb> <example><![CDATA[zend_extension=/absolute/path/to/apd.so apd.dumpdir=/tmp/traces]]></example> </slide> Index: presentations/slides/advanced/p_apd2.xml +++ presentations/slides/advanced/p_apd2.xml <slide title="Calling APD"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example title="Trace Dump"><![CDATA[<?php apd_set_pprof_trace(); // ... your code ?>]]></example> <example title="Browser Dump"><![CDATA[<?php apd_set_browser_trace(); // ... your code ?>]]></example> </slide> Index: presentations/slides/advanced/p_apd3.xml +++ presentations/slides/advanced/p_apd3.xml <slide title="APD Trace Analysis"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example fontsize="1.2em" filename="pres2.output"/> </slide> Index: presentations/slides/advanced/p_benchmark.xml +++ presentations/slides/advanced/p_benchmark.xml <slide title="Benchmarking"> <break/> <image filename="ninja.gif" align="right"/> <break lines="10"/> <blurb align="center" fontsize="4.0em"> Benchmarking allows you to compare alternative implementation in a sandboxed environment. </blurb> </slide> Index: presentations/slides/advanced/p_benchmark1.xml +++ presentations/slides/advanced/p_benchmark1.xml <slide title="Benchmarking"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> The two classes you need for benchmarking are %Benchmark_Timer% and %Benchmark_Iterate% </blurb> <break/> <example type="shell" title="Benchmark_Timer"><![CDATA[# pear install Benchmark_Timer]]></example> <break/> <example type="shell" title="Benchmark_Iterate"><![CDATA[# pear install Benchmark_Iterate]]></example> </slide> Index: presentations/slides/advanced/p_benchmark2.xml +++ presentations/slides/advanced/p_benchmark2.xml <slide title="Benchmark_Iterate"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example filename="arraybench.php" /> </slide> Index: presentations/slides/advanced/p_cacheability.xml +++ presentations/slides/advanced/p_cacheability.xml <slide title="External Cacheability"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="3.5em">Set %Cache-Control% headers so external caches know how to respect your content.</blurb> <break/> <example fontsize="1.8em"><![CDATA[Last-Modified: Mon, 22 Jul 2002 15:50:00 GMT Expires: Mon, 22 Jul 2002 15:52:25 GMT Cache-Control: must-revalidate, max-age=15, s-maxage=0, private]]></example> </slide> Index: presentations/slides/advanced/p_ccache.xml +++ presentations/slides/advanced/p_ccache.xml <slide title="Compiler Caches"> <break/> <image filename="ninja.gif" align="right" /> <break lines="4"/> <list fontsize="4.0em"> <bullet>fast = true</bullet> <bullet>Many available options</bullet> <bullet marginleft="2.0em">APC</bullet> <bullet marginleft="2.0em">Turck MMCache</bullet> <bullet marginleft="2.0em">ionCube</bullet> <bullet marginleft="2.0em">Zend Accelerator</bullet> </list> </slide> Index: presentations/slides/advanced/p_ccache1.xml +++ presentations/slides/advanced/p_ccache1.xml <slide title="Request Lifecycle"> <break/> <image filename="ninja.gif" align="right" /> <image filename="request.jpg" align="left" marginleft="1.0em"/> <break lines="10"/> <blurb fontsize="4.0em"> This happens for |ff0000|*every*| include file </blurb> <blurb fontsize="4.0em"> Compilation can easily consume more time than execution </blurb> </slide> Index: presentations/slides/advanced/p_ccache2.xml +++ presentations/slides/advanced/p_ccache2.xml <slide title="With Compiler Cache"> <break/> <image filename="ninja.gif" align="right" /> <image filename="ccache.jpg" align="left" marginleft="1.0em"/> <break lines="10"/> <blurb fontsize="4.0em"> Each source file is compiled once </blurb> <blurb fontsize="4.0em"> Expensive optimizations occur, but only once </blurb> <blurb fontsize="4.0em"> Dynamic includes do introduce their own, insignifigant, overhead </blurb> </slide> Index: presentations/slides/advanced/p_gzip.xml +++ presentations/slides/advanced/p_gzip.xml <slide title="mod_gzip"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> Use %mod_gzip% to compress your data before you send it over the wire </blurb> <blurb fontsize="4.0em"> %mod_gzip% is much better than php's built-in gzip compression </blurb> <blurb fontsize="4.0em"> But some encryption is better than none </blurb> </slide> Index: presentations/slides/advanced/p_io.xml +++ presentations/slides/advanced/p_io.xml <slide title="Output Buffering"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> System calls are expensive, %write()% is an inordinately expensive system call </blurb> <blurb fontsize="4.0em"> Set %output_buffering = On% in your PHP script </blurb> <blurb fontsize="4.0em"> Match your I/O sizes (%SendBufferSize% == %PageSize%) </blurb> </slide> Index: presentations/slides/advanced/p_perf.xml +++ presentations/slides/advanced/p_perf.xml <slide title="Performance Tuning"> <break/> <image filename="ninja.gif" align="right" /> <break lines="10"/> <blurb fontsize="4.0em" align="center"> ~Premature Optimization is the root of all evil~ </blurb> <blurb align="center" marginleft="2.0em" fontsize="4.0em">- Donald Knuth</blurb> </slide> Index: presentations/slides/advanced/p_profiling.xml +++ presentations/slides/advanced/p_profiling.xml <slide title="Profiling"> <break/> <image filename="ninja.gif" align="right"/> <break lines="8"/> <list marginleft="5.0em" fontsize="5.0em"> <bullet>Identify Bottlenecks</bullet> <bullet>Track Resource Usage</bullet> <bullet>Generate Call Trees</bullet> </list> </slide> Index: presentations/slides/advanced/p_squid.xml +++ presentations/slides/advanced/p_squid.xml <slide title="Squid Pre-generation"> <break/> <image filename="ninja.gif" align="right"/> <blurb fontsize="4.0em"> A neat way of handling pre-generation/static data caching is using Squid, which will cache the static portions of your website. </blurb> <image filename="squid1.png" align="center" /> </slide> Index: presentations/slides/advanced/p_truisms.xml +++ presentations/slides/advanced/p_truisms.xml <slide title="Some Truisms"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <list marginleft="2.0em"> <bullet fontsize="4.0em">Ahmdahl's Law</bullet> <bullet fontsize="4.0em">80/20 rule</bullet> </list> </slide> Index: presentations/slides/advanced/pres2.output +++ presentations/slides/advanced/pres2.output Trace for /data/www/pres2/index.php Total Elapsed Time = 2.46 Total System Time = 0.07 Total User Time = 2.11 Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 19.3 0.35 0.35 0.40 0.40 0.02 0.02 4625 0.0000 0.0000 0 strtolower 18.3 0.34 0.73 0.39 0.80 0.01 0.03 7481 0.0000 0.0000 0 xml_presentation->cdatahandler 11.5 0.25 0.25 0.25 0.25 0.00 0.00 2933 0.0000 0.0000 0 _pres_slide->_pres_slide 11.0 0.26 0.27 0.24 0.24 0.00 0.00 3712 0.0000 0.0000 0 xml_presentation->endhandler 10.6 0.27 0.27 0.23 0.23 0.00 0.00 5941 0.0000 0.0000 0 count 7.8 0.20 0.22 0.17 0.19 0.00 0.00 3612 0.0000 0.0000 0 xml_presentation->_add_attribs 4.6 0.14 0.83 0.10 0.73 0.00 0.00 3712 0.0000 0.0000 0 xml_presentation->starthandler 2.3 0.08 0.08 0.05 0.05 0.00 0.00 2 0.0000 0.0000 0 function_exists 1.8 0.04 0.04 0.03 0.03 0.01 0.01 912 0.0000 0.0000 0 method_exists 1.4 0.01 0.01 0.03 0.03 0.00 0.00 304 0.0000 0.0000 0 is_resource 1.4 0.07 0.07 0.03 0.03 0.00 0.00 2 0.0000 0.0000 0 is_array 1.4 0.02 0.02 0.03 0.03 0.00 0.00 76 0.0000 0.0000 0 fopen 0.9 0.14 0.14 0.02 0.02 0.00 0.00 304 0.0000 0.0000 0 get_parent_class 0.9 0.00 0.01 0.02 0.02 0.00 0.00 126 0.0000 0.0000 0 xml_presentation->iserror 0.9 0.02 0.02 0.01 0.01 0.01 0.01 202 0.0000 0.0000 0 fread 0.9 0.00 0.10 0.01 0.07 0.01 0.02 7 0.0000 0.0000 0 require_once 0.5 0.00 1.83 0.01 1.79 0.00 0.03 126 0.0000 0.0000 0 xml_presentation->parsestring 0.5 0.01 0.01 0.01 0.01 0.00 0.00 76 0.0000 0.0000 0 xml_presentation->seterrorhandling 0.5 0.02 0.02 0.01 0.01 0.00 0.00 76 0.0000 0.0000 0 _presentation->_presentation 0.5 0.02 0.02 0.01 0.01 0.00 0.00 10 0.0000 0.0000 0 define Index: presentations/slides/advanced/s_arch.xml +++ presentations/slides/advanced/s_arch.xml <slide title="Infrastructure"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em"> Infrastructure is the most common vulnerability. </blurb> <blurb fontsize="4.0em"> Even if Beavis and Butthead can't comprise your encryption, they can compromise your system. </blurb> <blurb fontsize="4.0em"> If you don't know how to secure a system, hire someone to do it. </blurb> </slide> Index: presentations/slides/advanced/s_encrypt.xml +++ presentations/slides/advanced/s_encrypt.xml <slide title="Cryptography"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <list fontsize="4.0em"> <bullet>Your data be not safe!</bullet> <bullet>I've hacked common webhosts in under 2 minutes</bullet> <bullet type="none" marginleft="2.0em">... and it required no more than %grep%</bullet> <bullet>You are liable for security breaches</bullet> <bullet type="none" marginleft="2.0em">... especially if you don't encrypt sensitive data</bullet> </list> </slide> Index: presentations/slides/advanced/s_encrypt1.xml +++ presentations/slides/advanced/s_encrypt1.xml <slide title="Roll your own"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="2"/> <blurb fontsize="4.0em"> My first attempt at encryption </blurb> <blurb fontsize="4.0em"> Ran on a piece of banking software for over 2 years. </blurb> <blurb fontsize="4.0em">%xor% anyone?</blurb> <example filename="sencrypt.pl" type="perl"/> </slide> Index: presentations/slides/advanced/s_encrypt2.xml +++ presentations/slides/advanced/s_encrypt2.xml <slide title="Mcrypt"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em"> Use the mcrypt extension which provides a rich set of "real" cryptography </blurb> <example filename="encryptsensitive.php"/> </slide> Index: presentations/slides/advanced/s_injection.xml +++ presentations/slides/advanced/s_injection.xml <slide title="Injection problems"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="8"/> <blurb fontsize="4.0em"> An example injection vulnerability is shown below </blurb> <example filename="inject.php"/> <blurb fontsize="4.0em"> What happens if I pass '%directory=/; rm -rf /%'? </blurb> </slide> Index: presentations/slides/advanced/s_injection1.xml +++ presentations/slides/advanced/s_injection1.xml <slide title="Injection problems"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>*Never* rely on the value of %magic_quotes_gpc%</bullet> <bullet>Escape SQL query variables with the native database functions when available</bullet> <bullet marginleft="2.0em">Use %AddSlashes()% when no better alternative exists</bullet> <bullet>Escape shell commands with %EscapeShellArg()% and %EscapeShellCmd()%</bullet> </list> </slide> Index: presentations/slides/advanced/s_security.xml +++ presentations/slides/advanced/s_security.xml <slide title="Security"> <break/> <image filename="bb.jpg" align="center"/> </slide> Index: presentations/slides/advanced/s_security1.xml +++ presentations/slides/advanced/s_security1.xml <slide title="Common Vulnerabilities"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>Error Handling problems</bullet> <bullet>Command injection</bullet> <bullet>SQL injection</bullet> <bullet>Unvalidated parameters</bullet> <bullet>Cross Site Scripting</bullet> <bullet>Insecure cryptography</bullet> </list> </slide> Index: presentations/slides/advanced/s_validation.xml +++ presentations/slides/advanced/s_validation.xml <slide title="Data Validation"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>Turn *off* %register_globals%. Access variables via %$_GET%, %$_POST%, %$_COOKIE%, etc.</bullet> <bullet type="none" marginleft="5.0em" effect="slide">... Dude, its faster! Heh! Hehe!</bullet> <bullet>Create specific parameters for input data, and make sure they match only that data</bullet> </list> <example><![CDATA[<?php if (!is_numerical($_GET['age']) && $_GET['age'] < 0 || $_GET['age'] > 200) { die("Invalid age given"); } ?>]]></example> </slide> Index: presentations/slides/advanced/s_validation1.xml +++ presentations/slides/advanced/s_validation1.xml <slide title="Data Tampering"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em">Do not allow users to manually modify hidden variables or cookies</blurb> <example filename="cookie.php"/> </slide> Index: presentations/slides/advanced/sencrypt.pl +++ presentations/slides/advanced/sencrypt.pl sub calc_checksum { $key = $_[0]; $sum = 0; $PI = 3.14; for ($x = 0; $x < length($key); $x++) { $sum += ord(substr($key, $x, 1)) * $PI; } return int $sum; } sub sencrypt { $data = $_[0]; $key = $_[1]; $sum = calc_checksum($key); for ($x = 0; $x < length($data); $x++) { $encrypted .= chr(ord(substr($data, $x, 1)) + $sum); } return $encrypted; } sub sdecrypt { $data = $_[0]; $key = $_[1]; $sum = calc_checksum($key); for ($x = 0; $x < length($data); $x++) { $decrypted .= chr(ord(substr($data, $x, 1)) - $sum); } return $decrypted; } Index: presentations/slides/advanced/simpleexcept.php +++ presentations/slides/advanced/simpleexcept.php <?php class ConnectException extends Exception { } function db_connect($host, $user, $pass) { if (mt_rand() % 6) { throw new Exception('Russian Roulette is fun'); } $conn = mysql_connect($host, $user, $pass); if (!$conn) { throw new ConnectException( sprintf('Cannot connect to host: %s', mysql_error()) ); } return $conn; } try { $conn = db_connect('localhost', 'user', 'pass'); } catch (ConnException $e) { echo $e->getMessage(); } catch (Exception $e) { echo $e->getMessage(); ?> Index: presentations/slides/advanced/thanks.xml +++ presentations/slides/advanced/thanks.xml <slide> <title>Thank You!</title> <blurb><![CDATA[<br />]]></blurb> <link fontsize="4.0em" align="left" leader="These Slides, " href="http://talks.php.net/"/> <link fontsize="4.0em" align="left" leader="My Email, " href="sterling@php.net"/> </slide>
Index: presentations/slides/advanced/d_knowledge1.xml diff -u presentations/slides/advanced/d_knowledge1.xml:1.2 presentations/slides/advanced/d_knowledge1.xml:1.3 --- presentations/slides/advanced/d_knowledge1.xml:1.2 Sun Jul 6 19:12:24 2003 +++ presentations/slides/advanced/d_knowledge1.xml Mon Jul 7 18:05:47 2003 @@ -7,6 +7,7 @@ <bullet>Wikis (coWiki, phpWiki)</bullet> <bullet>CVS</bullet> <bullet>CVSTrac (http://www.cvstrac.org/)</bullet> +<bullet>FIT (http://fit.c2.com/ - See the presentation this week)</bullet> </list> </slide> Index: presentations/slides/advanced/e_recieving.xml diff -u presentations/slides/advanced/e_recieving.xml:1.1 presentations/slides/advanced/e_recieving.xml:1.2 --- presentations/slides/advanced/e_recieving.xml:1.1 Sun Jul 6 19:12:24 2003 +++ presentations/slides/advanced/e_recieving.xml Mon Jul 7 18:05:47 2003 @@ -1,5 +1,27 @@ <slide title="Recieving"> -<blurb> +<break/> +<image filename="stonehenge.jpg" align="right" marginright="1.0em"/> +<blurb fontsize="4.0em"> +The classic manner of PHP error handling is to use lots and lots of +%if%'s. </blurb> +<example><![CDATA[<?php +$conn = mysql_connect('localhost', 'user', 'pass'); +if (!$conn) { + die("bah bah bear"); +} +if (!mysql_select_db('bing', $conn)) { + die("booh hoo hoo"); +} + +$stmt = mysql_query('select * baz from bar', $conn); +if (!$stmt) { + die("wah wah woo"); +} + +if (!mysql_num_rows($conn)) { + die("ding dong doo"); +} +?>]]></example> </slide> Index: presentations/slides/advanced/arraybench.php +++ presentations/slides/advanced/arraybench.php <?php require_once "Benchmark/Iterate.php"; $test_array = create_random_array(100); foreach(array('max', 'my_max') as $func) { $b = new Benchmark_Iterate; $b->run('10000', $func, $test_array); $result = $b->get(); print "$func\t"; printf("System + User Time: %1.6f\n", $result['mean']); } function create_random_array($size) { $array = array(); for($i=0; $i < $size; $i++) { $array[$i] = rand(); } return $array; } function my_max($array) { reset($array); $max = current($array); while( $el = next($array)) { if($el > $max) { $max = $el; } } return $max; } ?> Index: presentations/slides/advanced/cookie.php +++ presentations/slides/advanced/cookie.php <?php if (isset($_COOKIE['stamp'])) { if ($_COOKIE['stamp'] == md5($_COOKIE['data'] . 'SECRETKEY')) { echo "valid cookie\n"; } else { echo "tamper temper"; } } else { $_COOKIE['data'] = '00110100011'; $_COOKIE['stamp'] = md5($_COOKIE['data'] . 'SECRETKEY'); } ?> Index: presentations/slides/advanced/e_logging.xml +++ presentations/slides/advanced/e_logging.xml <slide title="Logging"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> Logging must be designed for extensibility </blurb> <blurb fontsize="4.0em"> When your application grows, logging can quickly become a bottleneck </blurb> <blurb fontsize="4.0em"> Use apache's logging facilities, extend with a custom module, eg, spread. </blurb> </slide> Index: presentations/slides/advanced/e_logging1.xml +++ presentations/slides/advanced/e_logging1.xml <slide title="The Humanity!"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> *Do Not* email yourself the logs for every failed message. Write high priority failures to a log file, and then email yourself that logfile (or the location of that logfile). </blurb> <blurb fontsize="4.0em"> If you are SMS' yourself failed error logs, you should consider investing in a second system administrator </blurb> <blurb fontsize="4.0em"> Make logs into test cases! </blurb> </slide> Index: presentations/slides/advanced/e_recieving1.xml +++ presentations/slides/advanced/e_recieving1.xml <slide title="Pull Error Handling"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <blurb fontsize="4.0em">%set_error_handler()% and %trigger_error()% are good tools for logging error messages</blurb> <blurb fontsize="4.0em">They *are not* a substitute for proper flow control statements</blurb> <example filename="errorhandler.php"/> </slide> Index: presentations/slides/advanced/e_recieving2.xml +++ presentations/slides/advanced/e_recieving2.xml <slide title="Exceptions"> <break/> <image filename="stonehenge.jpg" align="right" marginright="right"/> <break lines="5" /> <blurb fontsize="4.0em">Exceptions allow you to catch errors and change your flow control</blurb> <blurb fontsize="4.0em">They are incredibly useful when it comes to error handling</blurb> <blurb fontsize="4.0em">They are PHP *5* only</blurb> </slide> Index: presentations/slides/advanced/e_recieving3.xml +++ presentations/slides/advanced/e_recieving3.xml <slide title="Exception Example"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="6"/> <example filename="simpleexcept.php" /> </slide> Index: presentations/slides/advanced/e_shielding.xml +++ presentations/slides/advanced/e_shielding.xml <slide title="Shielding"> <break/> <image filename="stonehenge.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <blurb fontsize="4.0em"> Set %display_errors = Off% </blurb> <blurb fontsize="4.0em"> Use a custom error handler </blurb> <blurb fontsize="4.0em"> Log all error levels to different locations </blurb> </slide> Index: presentations/slides/advanced/encryptsensitive.php +++ presentations/slides/advanced/encryptsensitive.php <?php $key = 'Welcome to the monkey house' $s = 'cc-number-goes-here'; $alg = MCRYPT_BLOWFISH; $mode = MCRYPT_MODE_CBC; $iv = mcrypt_create_iv( mcrypt_get_iv_size($alg, $mode), MCRYPT_DEV_URANDOM ); $data = mcrypt_encrypt($alg, $key, $s, $mode, $iv); mysql_query( sprintf("INSERT INTO customers (iv, data) ('%s', '%s')", mysql_escape_string($iv), mysql_escape_string($data) ), $dbh ); ?> Index: presentations/slides/advanced/errorhandler.php +++ presentations/slides/advanced/errorhandler.php <?php function log_error_sqlite($errno, $errstr, $errfile, $errline) { global $edbh; if (!$edbh) { $edbh = sqlite_open("errors.sqlite"); sqlite_query( 'create table errors ( errno, errstr, errfile, errline )', $edbh); } sqlite_query(sprintf("insert into errors values ('%s', '%s', '%s', '%s')", sqlite_escape_string($errno), sqlite_escape_string($errstr), sqlite_escape_string($errfile), sqlite_escape_string($errline)), $edbh); } set_error_handler('log_error_sqlite'); $result = 1 / 0; ?> Index: presentations/slides/advanced/errors.sqlite +++ presentations/slides/advanced/errors.sqlite ** This file contains an SQLite 2.1 database ** (uãÚ Ð e etable errors errors 3 create table errors ( errno, errstr, errfile, errline ) " à t Z WZ2 Division by zero /data/www/pres2/presentations/slides/advanced/errorhandler.php 25 Z WZ2 Division by zero /data/www/pres2/presentations/slides/advanced/errorhandler.php 25 Index: presentations/slides/advanced/inject.php +++ presentations/slides/advanced/inject.php <?php $dir = $_GET['directory']; $contents = `ls $dir`; echo $contents; ?> Index: presentations/slides/advanced/p_apd.xml +++ presentations/slides/advanced/p_apd.xml <slide title="APD"> <break/> <image filename="ninja.gif" align="right"/> <image filename="apd.jpg" align="left"/> <break lines="10"/> <blurb fontsize="4.0em">Intercepts calls to %zend_execute%</blurb> <blurb fontsize="4.0em">Generates function call traces with timings</blurb> </slide> Index: presentations/slides/advanced/p_apd1.xml +++ presentations/slides/advanced/p_apd1.xml <slide title="Installing APD"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> Install APD via PEAR </blurb> <example type="shell"><![CDATA[# pear install apd % mkdir /tmp/traces]]></example> <blurb fontsize="4.0em"> Then add the following to your %php.ini% file: </blurb> <example><![CDATA[zend_extension=/absolute/path/to/apd.so apd.dumpdir=/tmp/traces]]></example> </slide> Index: presentations/slides/advanced/p_apd2.xml +++ presentations/slides/advanced/p_apd2.xml <slide title="Calling APD"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example title="Trace Dump"><![CDATA[<?php apd_set_pprof_trace(); // ... your code ?>]]></example> <example title="Browser Dump"><![CDATA[<?php apd_set_browser_trace(); // ... your code ?>]]></example> </slide> Index: presentations/slides/advanced/p_apd3.xml +++ presentations/slides/advanced/p_apd3.xml <slide title="APD Trace Analysis"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example fontsize="1.2em" filename="pres2.output"/> </slide> Index: presentations/slides/advanced/p_benchmark.xml +++ presentations/slides/advanced/p_benchmark.xml <slide title="Benchmarking"> <break/> <image filename="ninja.gif" align="right"/> <break lines="10"/> <blurb align="center" fontsize="4.0em"> Benchmarking allows you to compare alternative implementation in a sandboxed environment. </blurb> </slide> Index: presentations/slides/advanced/p_benchmark1.xml +++ presentations/slides/advanced/p_benchmark1.xml <slide title="Benchmarking"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> The two classes you need for benchmarking are %Benchmark_Timer% and %Benchmark_Iterate% </blurb> <break/> <example type="shell" title="Benchmark_Timer"><![CDATA[# pear install Benchmark_Timer]]></example> <break/> <example type="shell" title="Benchmark_Iterate"><![CDATA[# pear install Benchmark_Iterate]]></example> </slide> Index: presentations/slides/advanced/p_benchmark2.xml +++ presentations/slides/advanced/p_benchmark2.xml <slide title="Benchmark_Iterate"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <example filename="arraybench.php" /> </slide> Index: presentations/slides/advanced/p_cacheability.xml +++ presentations/slides/advanced/p_cacheability.xml <slide title="External Cacheability"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="3.5em">Set %Cache-Control% headers so external caches know how to respect your content.</blurb> <break/> <example fontsize="1.8em"><![CDATA[Last-Modified: Mon, 22 Jul 2002 15:50:00 GMT Expires: Mon, 22 Jul 2002 15:52:25 GMT Cache-Control: must-revalidate, max-age=15, s-maxage=0, private]]></example> </slide> Index: presentations/slides/advanced/p_ccache.xml +++ presentations/slides/advanced/p_ccache.xml <slide title="Compiler Caches"> <break/> <image filename="ninja.gif" align="right" /> <break lines="4"/> <list fontsize="4.0em"> <bullet>fast = true</bullet> <bullet>Many available options</bullet> <bullet marginleft="2.0em">APC</bullet> <bullet marginleft="2.0em">Turck MMCache</bullet> <bullet marginleft="2.0em">ionCube</bullet> <bullet marginleft="2.0em">Zend Accelerator</bullet> </list> </slide> Index: presentations/slides/advanced/p_ccache1.xml +++ presentations/slides/advanced/p_ccache1.xml <slide title="Request Lifecycle"> <break/> <image filename="ninja.gif" align="right" /> <image filename="request.jpg" align="left" marginleft="1.0em"/> <break lines="10"/> <blurb fontsize="4.0em"> This happens for |ff0000|*every*| include file </blurb> <blurb fontsize="4.0em"> Compilation can easily consume more time than execution </blurb> </slide> Index: presentations/slides/advanced/p_ccache2.xml +++ presentations/slides/advanced/p_ccache2.xml <slide title="With Compiler Cache"> <break/> <image filename="ninja.gif" align="right" /> <image filename="ccache.jpg" align="left" marginleft="1.0em"/> <break lines="10"/> <blurb fontsize="4.0em"> Each source file is compiled once </blurb> <blurb fontsize="4.0em"> Expensive optimizations occur, but only once </blurb> <blurb fontsize="4.0em"> Dynamic includes do introduce their own, insignifigant, overhead </blurb> </slide> Index: presentations/slides/advanced/p_gzip.xml +++ presentations/slides/advanced/p_gzip.xml <slide title="mod_gzip"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> Use %mod_gzip% to compress your data before you send it over the wire </blurb> <blurb fontsize="4.0em"> %mod_gzip% is much better than php's built-in gzip compression </blurb> <blurb fontsize="4.0em"> But some encryption is better than none </blurb> </slide> Index: presentations/slides/advanced/p_io.xml +++ presentations/slides/advanced/p_io.xml <slide title="Output Buffering"> <break/> <image filename="ninja.gif" align="right"/> <break lines="4"/> <blurb fontsize="4.0em"> System calls are expensive, %write()% is an inordinately expensive system call </blurb> <blurb fontsize="4.0em"> Set %output_buffering = On% in your PHP script </blurb> <blurb fontsize="4.0em"> Match your I/O sizes (%SendBufferSize% == %PageSize%) </blurb> </slide> Index: presentations/slides/advanced/p_perf.xml +++ presentations/slides/advanced/p_perf.xml <slide title="Performance Tuning"> <break/> <image filename="ninja.gif" align="right" /> <break lines="10"/> <blurb fontsize="4.0em" align="center"> ~Premature Optimization is the root of all evil~ </blurb> <blurb align="center" marginleft="2.0em" fontsize="4.0em">- Donald Knuth</blurb> </slide> Index: presentations/slides/advanced/p_profiling.xml +++ presentations/slides/advanced/p_profiling.xml <slide title="Profiling"> <break/> <image filename="ninja.gif" align="right"/> <break lines="8"/> <list marginleft="5.0em" fontsize="5.0em"> <bullet>Identify Bottlenecks</bullet> <bullet>Track Resource Usage</bullet> <bullet>Generate Call Trees</bullet> </list> </slide> Index: presentations/slides/advanced/p_squid.xml +++ presentations/slides/advanced/p_squid.xml <slide title="Squid Pre-generation"> <break/> <image filename="ninja.gif" align="right"/> <blurb fontsize="4.0em"> A neat way of handling pre-generation/static data caching is using Squid, which will cache the static portions of your website. </blurb> <image filename="squid1.png" align="center" /> </slide> Index: presentations/slides/advanced/p_truisms.xml +++ presentations/slides/advanced/p_truisms.xml <slide title="Some Truisms"> <break/> <image filename="ninja.gif" align="right"/> <break lines="5"/> <list marginleft="2.0em"> <bullet fontsize="4.0em">Ahmdahl's Law</bullet> <bullet fontsize="4.0em">80/20 rule</bullet> </list> </slide> Index: presentations/slides/advanced/pres2.output +++ presentations/slides/advanced/pres2.output Trace for /data/www/pres2/index.php Total Elapsed Time = 2.46 Total System Time = 0.07 Total User Time = 2.11 Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 19.3 0.35 0.35 0.40 0.40 0.02 0.02 4625 0.0000 0.0000 0 strtolower 18.3 0.34 0.73 0.39 0.80 0.01 0.03 7481 0.0000 0.0000 0 xml_presentation->cdatahandler 11.5 0.25 0.25 0.25 0.25 0.00 0.00 2933 0.0000 0.0000 0 _pres_slide->_pres_slide 11.0 0.26 0.27 0.24 0.24 0.00 0.00 3712 0.0000 0.0000 0 xml_presentation->endhandler 10.6 0.27 0.27 0.23 0.23 0.00 0.00 5941 0.0000 0.0000 0 count 7.8 0.20 0.22 0.17 0.19 0.00 0.00 3612 0.0000 0.0000 0 xml_presentation->_add_attribs 4.6 0.14 0.83 0.10 0.73 0.00 0.00 3712 0.0000 0.0000 0 xml_presentation->starthandler 2.3 0.08 0.08 0.05 0.05 0.00 0.00 2 0.0000 0.0000 0 function_exists 1.8 0.04 0.04 0.03 0.03 0.01 0.01 912 0.0000 0.0000 0 method_exists 1.4 0.01 0.01 0.03 0.03 0.00 0.00 304 0.0000 0.0000 0 is_resource 1.4 0.07 0.07 0.03 0.03 0.00 0.00 2 0.0000 0.0000 0 is_array 1.4 0.02 0.02 0.03 0.03 0.00 0.00 76 0.0000 0.0000 0 fopen 0.9 0.14 0.14 0.02 0.02 0.00 0.00 304 0.0000 0.0000 0 get_parent_class 0.9 0.00 0.01 0.02 0.02 0.00 0.00 126 0.0000 0.0000 0 xml_presentation->iserror 0.9 0.02 0.02 0.01 0.01 0.01 0.01 202 0.0000 0.0000 0 fread 0.9 0.00 0.10 0.01 0.07 0.01 0.02 7 0.0000 0.0000 0 require_once 0.5 0.00 1.83 0.01 1.79 0.00 0.03 126 0.0000 0.0000 0 xml_presentation->parsestring 0.5 0.01 0.01 0.01 0.01 0.00 0.00 76 0.0000 0.0000 0 xml_presentation->seterrorhandling 0.5 0.02 0.02 0.01 0.01 0.00 0.00 76 0.0000 0.0000 0 _presentation->_presentation 0.5 0.02 0.02 0.01 0.01 0.00 0.00 10 0.0000 0.0000 0 define Index: presentations/slides/advanced/s_arch.xml +++ presentations/slides/advanced/s_arch.xml <slide title="Infrastructure"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em"> Infrastructure is the most common vulnerability. </blurb> <blurb fontsize="4.0em"> Even if Beavis and Butthead can't comprise your encryption, they can compromise your system. </blurb> <blurb fontsize="4.0em"> If you don't know how to secure a system, hire someone to do it. </blurb> </slide> Index: presentations/slides/advanced/s_encrypt.xml +++ presentations/slides/advanced/s_encrypt.xml <slide title="Cryptography"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="5"/> <list fontsize="4.0em"> <bullet>Your data be not safe!</bullet> <bullet>I've hacked common webhosts in under 2 minutes</bullet> <bullet type="none" marginleft="2.0em">... and it required no more than %grep%</bullet> <bullet>You are liable for security breaches</bullet> <bullet type="none" marginleft="2.0em">... especially if you don't encrypt sensitive data</bullet> </list> </slide> Index: presentations/slides/advanced/s_encrypt1.xml +++ presentations/slides/advanced/s_encrypt1.xml <slide title="Roll your own"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="2"/> <blurb fontsize="4.0em"> My first attempt at encryption </blurb> <blurb fontsize="4.0em"> Ran on a piece of banking software for over 2 years. </blurb> <blurb fontsize="4.0em">%xor% anyone?</blurb> <example filename="sencrypt.pl" type="perl"/> </slide> Index: presentations/slides/advanced/s_encrypt2.xml +++ presentations/slides/advanced/s_encrypt2.xml <slide title="Mcrypt"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em"> Use the mcrypt extension which provides a rich set of "real" cryptography </blurb> <example filename="encryptsensitive.php"/> </slide> Index: presentations/slides/advanced/s_injection.xml +++ presentations/slides/advanced/s_injection.xml <slide title="Injection problems"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="8"/> <blurb fontsize="4.0em"> An example injection vulnerability is shown below </blurb> <example filename="inject.php"/> <blurb fontsize="4.0em"> What happens if I pass '%directory=/; rm -rf /%'? </blurb> </slide> Index: presentations/slides/advanced/s_injection1.xml +++ presentations/slides/advanced/s_injection1.xml <slide title="Injection problems"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>*Never* rely on the value of %magic_quotes_gpc%</bullet> <bullet>Escape SQL query variables with the native database functions when available</bullet> <bullet marginleft="2.0em">Use %AddSlashes()% when no better alternative exists</bullet> <bullet>Escape shell commands with %EscapeShellArg()% and %EscapeShellCmd()%</bullet> </list> </slide> Index: presentations/slides/advanced/s_security.xml +++ presentations/slides/advanced/s_security.xml <slide title="Security"> <break/> <image filename="bb.jpg" align="center"/> </slide> Index: presentations/slides/advanced/s_security1.xml +++ presentations/slides/advanced/s_security1.xml <slide title="Common Vulnerabilities"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>Error Handling problems</bullet> <bullet>Command injection</bullet> <bullet>SQL injection</bullet> <bullet>Unvalidated parameters</bullet> <bullet>Cross Site Scripting</bullet> <bullet>Insecure cryptography</bullet> </list> </slide> Index: presentations/slides/advanced/s_validation.xml +++ presentations/slides/advanced/s_validation.xml <slide title="Data Validation"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <list fontsize="4.0em"> <bullet>Turn *off* %register_globals%. Access variables via %$_GET%, %$_POST%, %$_COOKIE%, etc.</bullet> <bullet type="none" marginleft="5.0em" effect="slide">... Dude, its faster! Heh! Hehe!</bullet> <bullet>Create specific parameters for input data, and make sure they match only that data</bullet> </list> <example><![CDATA[<?php if (!is_numerical($_GET['age']) && $_GET['age'] < 0 || $_GET['age'] > 200) { die("Invalid age given"); } ?>]]></example> </slide> Index: presentations/slides/advanced/s_validation1.xml +++ presentations/slides/advanced/s_validation1.xml <slide title="Data Tampering"> <break/> <image filename="bb-small.jpg" align="right" marginright="1.0em"/> <break lines="4"/> <blurb fontsize="4.0em">Do not allow users to manually modify hidden variables or cookies</blurb> <example filename="cookie.php"/> </slide> Index: presentations/slides/advanced/sencrypt.pl +++ presentations/slides/advanced/sencrypt.pl sub calc_checksum { $key = $_[0]; $sum = 0; $PI = 3.14; for ($x = 0; $x < length($key); $x++) { $sum += ord(substr($key, $x, 1)) * $PI; } return int $sum; } sub sencrypt { $data = $_[0]; $key = $_[1]; $sum = calc_checksum($key); for ($x = 0; $x < length($data); $x++) { $encrypted .= chr(ord(substr($data, $x, 1)) + $sum); } return $encrypted; } sub sdecrypt { $data = $_[0]; $key = $_[1]; $sum = calc_checksum($key); for ($x = 0; $x < length($data); $x++) { $decrypted .= chr(ord(substr($data, $x, 1)) - $sum); } return $decrypted; } Index: presentations/slides/advanced/simpleexcept.php +++ presentations/slides/advanced/simpleexcept.php <?php class ConnectException extends Exception { } function db_connect($host, $user, $pass) { if (mt_rand() % 6) { throw new Exception('Russian Roulette is fun'); } $conn = mysql_connect($host, $user, $pass); if (!$conn) { throw new ConnectException( sprintf('Cannot connect to host: %s', mysql_error()) ); } return $conn; } try { $conn = db_connect('localhost', 'user', 'pass'); } catch (ConnException $e) { echo $e->getMessage(); } catch (Exception $e) { echo $e->getMessage(); ?> Index: presentations/slides/advanced/thanks.xml +++ presentations/slides/advanced/thanks.xml <slide> <title>Thank You!</title> <blurb><![CDATA[<br />]]></blurb> <link fontsize="4.0em" align="left" leader="These Slides, " href="http://talks.php.net/"/> <link fontsize="4.0em" align="left" leader="My Email, " href="sterling@php.net"/> </slide>