cvs: presentations / php-best-practices.xml /slides/php-best-practices about.xml aboutme-kore.xml aboutme-toby.xml agenda.xml caching.png end.xml
error_plain.png error_xdebug.png general-agenda.xml general-codingstandard.xml general-debugging1.xml general-debugging2.xml general-documentation.xml
general-e_strict.xml general-exceptions.xml general-intro.xml general-reinventwheel.xml general-shortopen.xml general-typesafe1.xml
general-typesafe2.xml opcache.png open-intro.xml performance-agenda.xml performance-caching1.xml performance-caching2.xml performance-cvsphp.xml
performance-intro.xml performance-mod_gzip.xml performance-oo.xml performance-opcodecache1.xml performance-opcodecache2.xml performance-profiling.xml
performance-regex.xml performance-simple.xml php-best-practices.xml security-agenda.xml security-configuration-1.xml security-configuration-2.xml
security-cookies.xml security-input.xml security-intro.xml security-obscurity.xml security-permissions.xml se! curity-sql.xml security-variables_1.xml
security-variables_2.xml security-xss.xml talk.css thanks.xml title.xml
| From: | Tobias Schlitt | Date: | Sun, 25 Jun 2006 10:55:21 +0000 |
| Subject: | cvs: presentations / php-best-practices.xml /slides/php-best-practices about.xml aboutme-kore.xml aboutme-toby.xml agenda.xml caching.png end.xml error_plain.png error_xdebug.png general-agenda.xml general-codingstandard.xml general-debugging1.xml general-debugging2.xml general-documentation.xml general-e_strict.xml general-exceptions.xml general-intro.xml general-reinventwheel.xml general-shortopen.xml general-typesafe1.xml general-typesafe2.xml opcache.png open-intro.xml performance-agenda.xml performance-caching1.xml performance-caching2.xml performance-cvsphp.xml performance-intro.xml performance-mod_gzip.xml performance-oo.xml performance-opcodecache1.xml performance-opcodecache2.xml performance-profiling.xml performance-regex.xml performance-simple.xml php-best-practices.xml security-agenda.xml security-configuration-1.xml security-configuration-2.xml security-cookies.xml security-input.xml security-intro.xml security-obscurity.xml security-permissions.xml se! curity-sql.xml security-variables_1.xml security-variables_2.xml security-xss.xml talk.css thanks.xml title.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1328@lists.php.net to get a copy of this message | ||
toby Sun Jun 25 10:55:21 2006 UTC
Added files:
/presentations php-best-practices.xml
/presentations/slides/php-best-practices about.xml aboutme-kore.xml
aboutme-toby.xml
agenda.xml caching.png
end.xml error_plain.png
error_xdebug.png
general-agenda.xml
general-codingstandard.xml
general-debugging1.xml
general-debugging2.xml
general-documentation.xml
general-e_strict.xml
general-exceptions.xml
general-intro.xml
general-reinventwheel.xml
general-shortopen.xml
general-typesafe1.xml
general-typesafe2.xml
opcache.png open-intro.xml
performance-agenda.xml
performance-caching1.xml
performance-caching2.xml
performance-cvsphp.xml
performance-intro.xml
performance-mod_gzip.xml
performance-oo.xml
performance-opcodecache1.xml
performance-opcodecache2.xml
performance-profiling.xml
performance-regex.xml
performance-simple.xml
php-best-practices.xml
security-agenda.xml
security-configuration-1.xml
security-configuration-2.xml
security-cookies.xml
security-input.xml
security-intro.xml
security-obscurity.xml
security-permissions.xml
security-sql.xml
security-variables_1.xml
security-variables_2.xml
security-xss.xml talk.css
thanks.xml title.xml
Log:
- Adding slides from FrOSCon conference.
http://cvs.php.net/viewvc.cgi/presentations/php-best-practices.xml?view=markup&rev=1.1 Index: presentations/php-best-practices.xml +++ presentations/php-best-practices.xml <?xml version="1.0" encoding="iso-8859-1"?> <presentation template="css" navmode="html" navbarbackground="#4373b4" navbartopiclinks="0" navColor="#f1fbff" logo1="" stylesheet="presentations/slides/php-best-practices/talk.css" backgroundfixed="1" > <topic>PHP</topic> <title>PHP best practices - The dos and don'ts</title> <event>Free and Open Source software Conference</event> <location>St. Augustin, Germany</location> <date>June 24th, 2006</date> <speaker>Tobias Schlitt & Kore Nordmann</speaker> <email>ts@ez.no & kn@ez.no</email> <!-- Intro --> <slide>slides/php-best-practices/title.xml</slide> <slide>slides/php-best-practices/aboutme-kore.xml</slide> <slide>slides/php-best-practices/aboutme-toby.xml</slide> <slide>slides/php-best-practices/agenda.xml</slide> <!-- About this talk --> <slide>slides/php-best-practices/about.xml</slide> <!-- General --> <slide>slides/php-best-practices/general-intro.xml</slide> <slide>slides/php-best-practices/general-agenda.xml</slide> <slide>slides/php-best-practices/general-typesafe1.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-shortopen.xml</slide> <slide>slides/php-best-practices/general-e_strict.xml</slide> <slide>slides/php-best-practices/general-exceptions.xml</slide> <slide>slides/php-best-practices/general-debugging1.xml</slide> <slide>slides/php-best-practices/general-debugging2.xml</slide> <slide>slides/php-best-practices/general-codingstandard.xml</slide> <slide>slides/php-best-practices/general-documentation.xml</slide> <!-- Security --> <slide>slides/php-best-practices/security-intro.xml</slide> <slide>slides/php-best-practices/security-agenda.xml</slide> <slide>slides/php-best-practices/security-variables_1.xml</slide> <slide>slides/php-best-practices/security-variables_2.xml</slide> <slide>slides/php-best-practices/security-sql.xml</slide> <slide>slides/php-best-practices/security-input.xml</slide> <slide>slides/php-best-practices/security-xss.xml</slide> <slide>slides/php-best-practices/security-obscurity.xml</slide> <slide>slides/php-best-practices/security-permissions.xml</slide> <slide>slides/php-best-practices/security-configuration-1.xml</slide> <slide>slides/php-best-practices/security-configuration-2.xml</slide> <slide>slides/php-best-practices/security-cookies.xml</slide> <!-- Performance --> <slide>slides/php-best-practices/performance-intro.xml</slide> <slide>slides/php-best-practices/performance-agenda.xml</slide> <slide>slides/php-best-practices/performance-cvsphp.xml</slide> <slide>slides/php-best-practices/performance-simple.xml</slide> <slide>slides/php-best-practices/performance-oo.xml</slide> <slide>slides/php-best-practices/performance-caching1.xml</slide> <slide>slides/php-best-practices/performance-caching2.xml</slide> <slide>slides/php-best-practices/performance-regex.xml</slide> <slide>slides/php-best-practices/performance-opcodecache1.xml</slide> <slide>slides/php-best-practices/performance-opcodecache2.xml</slide> <slide>slides/php-best-practices/performance-profiling.xml</slide> <slide>slides/php-best-practices/performance-mod_gzip.xml</slide> <!-- Open part --> <slide>slides/php-best-practices/open-intro.xml</slide> <slide>slides/php-best-practices/end.xml</slide> </presentation> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/about.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/about.xml +++ presentations/slides/php-best-practices/about.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>About this talk</title> <blurb>Why should you attend this talk?</blurb> <list> <bullet>PHP is easy to learn, but hard to master</bullet> <bullet>Security issues are lurking everywhere</bullet> <bullet>Performance is important, especially for a scripting language</bullet> <bullet>Open source should be "nice looking"</bullet> </list> <blurb>What will I learn here?</blurb> <list> <bullet>A lot of common mistakes so you can avoid them</bullet> <bullet>A lot of common tricks you can use</bullet> <bullet>Some nice tools to make your work more easy and secure</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/aboutme-kore.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/aboutme-kore.xml +++ presentations/slides/php-best-practices/aboutme-kore.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="About us - Kore"> <list> <bullet>Kore Nordmann <kn@ez.no></bullet> <bullet>Studies computer science at the university of Dortmund</bullet> <bullet>Working for eZ systems on the eZ components</bullet> <bullet>Member of the PEAR project</bullet> <bullet>PHP Usergroup Dortmund</bullet> </list> <break /> <break /> <list> <bullet>http://ez.no</bullet> <bullet>http://kore-nordmann.de</bullet> <bullet>http://phpugdo.de</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/aboutme-toby.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/aboutme-toby.xml +++ presentations/slides/php-best-practices/aboutme-toby.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="About us - Toby"> <list> <bullet>Tobias Schlitt <ts@ez.no></bullet> <bullet>IT specialist, currently studying computer science</bullet> <bullet>Working for eZ systems on the eZ components</bullet> <bullet>Member of the PEAR project</bullet> <bullet>PHP Usergroup Dortmund</bullet> </list> <break /> <break /> <list> <bullet>http://ez.no</bullet> <bullet>http://schlitt.info</bullet> <bullet>http://phpugdo.de</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/agenda.xml +++ presentations/slides/php-best-practices/agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="6em"> <title>Agenda</title> <list> <bullet>About this talk</bullet> <bullet>General dos and don'ts</bullet> <bullet>Security</bullet> <bullet>Performance</bullet> <bullet>Open part</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/end.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/end.xml +++ presentations/slides/php-best-practices/end.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>The end</title> <blurb>Thanks for listening!</blurb> <blurb>We hope you...</blurb> <list> <bullet>... learned what you hoped to learn</bullet> <bullet>... code better PHP now</bullet> <bullet>... possibly slept well ;)</bullet> </list> <blurb>This slides online:</blurb> <list> <bullet>http://talks.php.net</bullet> </list> <blurb>Reaching us:</blurb> <list> <bullet>Kore Nordmann <kn@ez.no></bullet> <bullet>Tobias Schlitt <ts@ez.no></bullet> </list> <blurb>Some important websites:</blurb> <list> <bullet>http://hardened-php.net</bullet> <bullet>http://planet-php.net</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-agenda.xml +++ presentations/slides/php-best-practices/general-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Agenda</title> <list> <bullet>Type safe coding</bullet> <bullet>Bad short open tags</bullet> <bullet>Being E_STRICT</bullet> <bullet>Exceptions</bullet> <bullet>Using a debugger</bullet> <bullet>Avoid reinventing the wheel</bullet> <bullet>Why coding standards are good</bullet> <bullet>Documentation</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-codingstandard.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-codingstandard.xml +++ presentations/slides/php-best-practices/general-codingstandard.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Codingstandard</title> <blurb>The issue: "I code like I want to!"</blurb> <list> <bullet>Other people have difficulties to read the code (open source)</bullet> <bullet>Maybe someone needs to take over maintainance of your code</bullet> <bullet>You might stumble yourself over it once upon a time</bullet> </list> <blurb>The solution: Coding standards</blurb> <list> <bullet>PEAR http://pear.php.net/manual/en/standards.php</bullet> <bullet>eZ systems http://ez.no/products/ez_publish/documentation/development/standards/php</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-debugging1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-debugging1.xml +++ presentations/slides/php-best-practices/general-debugging1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Using a debugger - 1</title> <blurb>The issue: "I don't need a debugger".</blurb> <list> <bullet>"var_dump(), print_r() and echo also do the job!"</bullet> <bullet>PHPs error messages are quite useless</bullet> <bullet>A debugger has some really neat features that save time and headache</bullet> </list> <example result="0"><![CDATA[<?php function foo() { phpinfo("bar"); } foo(); ?>]]></example> <blurb>Looks in plain PHP like this</blurb> <image align="center" filename="error_plain.png" pdf-scale="0.7"/> <blurb>Looks with a good debugger like this</blurb> <image align="center" filename="error_xdebug.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-debugging2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-debugging2.xml +++ presentations/slides/php-best-practices/general-debugging2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Using a debugger - 2</title> <blurb>The solution: Use a good debugger!</blurb> <blurb>Recommendation: Xdebug (http://xdebug.org)</blurb> <list> <bullet>Open source</bullet> <bullet>Wide spreaded and used</bullet> <bullet>Integrates as a PHP extension</bullet> <bullet>Integration with IDEs (like Comodo)</bullet> <bullet>Support for profiling and code-coverage analysis</bullet> </list> <blurb>Some other debuggers:</blurb> <list> <bullet>DBG http://dd.cron.ru/</bullet> <bullet>APD http://apd.communityconnect.com/</bullet> <bullet>Zend IDE (commercial) http://zend.com</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-documentation.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-documentation.xml +++ presentations/slides/php-best-practices/general-documentation.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Documentation</title> <blurb>The issue: Documentation is the most boring work</blurb> <list> <bullet>Re-read your code 6 month after you wrote it!</bullet> <bullet>Think about people who have to use your code</bullet> </list> <blurb>The solution: phpDocumentor</blurb> <list> <bullet>Implementation of JavaDoc for PHP</bullet> <bullet>Community accepted standard</bullet> <bullet>Avaiable through PEAR</bullet> <bullet>Allows auto-generation of API docs</bullet> <bullet>Also works for tutorials</bullet> <bullet>http://phpdoc.org</bullet> </list> <blurb>Useful hints</blurb> <list> <bullet>Write docs before implementing the code!</bullet> <bullet>You will probably not do it, if you do the other way around</bullet> <bullet>Document pedantically, fixing docs later sucks!</bullet> <bullet>Get used to update the docs, as soon as you change the code</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-e_strict.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-e_strict.xml +++ presentations/slides/php-best-practices/general-e_strict.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Being E_STRICT</title> <blurb>The issue: PHP has a new error level E_STRICT, since PHP 5.0.</blurb> <list> <bullet>E_STRICT forces you to code clean PHP 5 code</bullet> <bullet>Current E_STRICT will most probably become E_FATAL in PHP 6.0</bullet> <bullet>The resolution: Switch E_STRICT on and check your code</bullet> </list> <example result="0"><![CDATA[error_reporting=E_ALL | E_STRICT]]></example> <blurb>Typical E_STRICT error - Usage of outdated is_a() function</blurb> <example result="0"><![CDATA[<?php if ( is_a( $object, 'ClassName' ) ) { $object->foo(); } ?>]]></example> <blurb>Should be now</blurb> <example result="0"><![CDATA[<?php if ( $object instanceof ClassName ) { $object->foo(); } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-exceptions.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-exceptions.xml +++ presentations/slides/php-best-practices/general-exceptions.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Exceptions</title> <blurb>The issue: PHP has exceptions now, cool but dangerous.</blurb> <list> <bullet>Exceptions are a great tool for handling exceptional states</bullet> <bullet>Exceptions are often misused and become regulars</bullet> <bullet>Exceptions may make PHP leaking</bullet> </list> <example result="0"><![CDATA[<?php function foo() { if ($user_input !== "Hello!") { throw new Exception("User input wrong"); } } ?>]]></example> <blurb>Only use exceptions, when your application ends up in an exceptional state</blurb> <example result="0"><![CDATA[<?php function bar() { if (connection_timedout()) { throw new Exception("Connection timeout"); } } ?>]]></example> <blurb>Exceptions leak a little bit of memory when thrown e.g. out of for loops</blurb> <example result="0"><![CDATA[<?php foreach ($i = 1000000; $i > 0; $i--) { throw new Exceptions("Hehe, I'm leaking"); } ?>]]></example> <blurb>Allocated memory from the for-loop-header is not freeed correctly.</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-intro.xml +++ presentations/slides/php-best-practices/general-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common good manners for coding PHP</bullet> <bullet>Nice tips for clean PHP code</bullet> <bullet>Behaviours to avoid common mistakes</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-reinventwheel.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-reinventwheel.xml +++ presentations/slides/php-best-practices/general-reinventwheel.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Do not reinvent the wheel</title> <blurb>The issue: "I code everything on my own!"</blurb> <list> <bullet>Some people really code everything themselves</bullet> <bullet>This costs time and causes headache</bullet> <bullet>Errors occur more often in 1-maintained code</bullet> </list> <blurb>The solution: Access libraries like...</blurb> <list> <bullet>eZ components http://ez.no/products/ez_components</bullet> <bullet>Zend Framework http://framework.zend.com/</bullet> <bullet>PEAR http://pear.php.net/</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-shortopen.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-shortopen.xml +++ presentations/slides/php-best-practices/general-shortopen.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Bad short open tags</title> <blurb>The issue: PHP allows several open tags beside <![CDATA["<?php"]]>.</blurb> <example result="0"><![CDATA[<? echo "Hello world"; ?>]]></example> <blurb>Or, even worse.</blurb> <example result="0"><![CDATA[<?="Hello world"; ?>]]></example> <blurb>Or worst:</blurb> <example result="0"><![CDATA[<% echo "Hello world"; %>]]></example> <list> <bullet><![CDATA[<?]]> on its own is reserved for XML declaration</bullet> <bullet><![CDATA[<?=]]> is complete invalid XML</bullet> <bullet><![CDATA[<%]]> is ASP style and sucks</bullet> <bullet>All styles beside the official <![CDATA[<?php ... ?>]]> are deprecated</bullet> </list> <blurb>The solution: Stick to standard tags and convert all your scripts!</blurb> <list> <bullet>Guaranteed to be supported further</bullet> <bullet>Represents a valid XML processing instruction</bullet> <bullet>Unique in all PHP documents</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-typesafe1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-typesafe1.xml +++ presentations/slides/php-best-practices/general-typesafe1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Type safe coding - 1</title> <blurb>The issue: In general PHP is loosely typed.</blurb> <example result="1"><![CDATA[<?php $foo = "1"; $bar = $foo + 1; var_dump($foo, $bar); ?>]]></example> <blurb>The normal comparison operators are loosely typed, too.</blurb> <example result="1"><![CDATA[<?php $int = 1; $string = "1"; $bool = true; var_dump($int == $string); var_dump($string == $bool); var_dump($int == $bool); ?>]]></example> <blurb>This can cause WTF situations</blurb> <example result="1"><![CDATA[<?php var_dump( '1' == '1.' ); ?>]]></example> <blurb>This may lead to very common mistakes:</blurb> <example result="1"><![CDATA[<?php function foo($answer) { if ($answer > 10) { return true; } else { return $answer; } } if (foo(11)) { echo "11 is greater 10<br />"; } if (foo(9)) { echo "9 is greater than 10<br />"; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-typesafe2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-typesafe2.xml +++ presentations/slides/php-best-practices/general-typesafe2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Type safe coding - 2</title> <blurb>The solution: Type safe coding.</blurb> <example result="1"><![CDATA[<?php $foo = "1"; $bar = (int)$foo + 1; var_dump((int)$foo, $bar); ?>]]></example> <blurb>Use the type safe comparison operators.</blurb> <example result="1"><![CDATA[<?php $int = 1; $string = "1"; $bool = true; var_dump($int === $string); var_dump($string === $bool); var_dump($int === $bool); ?>]]></example> <blurb>The shown mistake is gone:</blurb> <example result="1"><![CDATA[<?php function foo($answer) { if ($answer > 10) { return true; } else { return $answer; } } if (foo(11) === true) { echo "11 is greater 10<br />"; } if (foo(9) === true) { echo "9 is greater than 10<br />"; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/open-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/open-intro.xml +++ presentations/slides/php-best-practices/open-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Open part</title> <blurb>Now it is time for...</blurb> <list> <bullet>Discussion</bullet> <bullet>Questions and answers</bullet> <bullet>Critics</bullet> <bullet>Chatting</bullet> <bullet>...</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-agenda.xml +++ presentations/slides/php-best-practices/performance-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Agenda</title> <list> <bullet>Prefer C over PHP</bullet> <bullet>Simple speed enhancements</bullet> <bullet>Keep OO within a limit</bullet> <bullet>Cache as much as possible</bullet> <bullet>Watch your regex</bullet> <bullet>OP code caching</bullet> <bullet>Profiling</bullet> <bullet>mod_gzip</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-caching1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-caching1.xml +++ presentations/slides/php-best-practices/performance-caching1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Caching - 1</title> <blurb>The issue: Most content is not dynamic content!</blurb> <list> <bullet>90% of the time your website generates the same data again</bullet> <bullet>Each requests results in the same database results</bullet> <bullet>90% of the performance of your server is to perform useles work</bullet> </list> <blurb>The solution: Caching, caching, caching</blurb> <list> <bullet>Think how often your content (or pieces of it) is regenerated</bullet> <bullet>Cache it in between!</bullet> <bullet>Think about publishing based caching</bullet> </list> <blurb>Good caching classes</blurb> <list> <bullet>eZ Cache (http://ez.no/products/ez_components)</bullet> <bullet>Cache_Lite (http://pear.php.net/Cache_Lite</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-caching2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-caching2.xml +++ presentations/slides/php-best-practices/performance-caching2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Caching - 2</title> <image align="center" filename="caching.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-cvsphp.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-cvsphp.xml +++ presentations/slides/php-best-practices/performance-cvsphp.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - C versus PHP</title> <blurb>The issue: PHP functions are faster than userland functions</blurb> <list> <bullet>PHP internal functions save a lot of time</bullet> <bullet>Still users tend to write the most basic functions in userland</bullet> </list> <blurb>The solution: Read the manual!</blurb> <list> <bullet>PHP has wonderful docs! Learn to love them!</bullet> <bullet>Before implementing a basic function on your own, check if it exists in PHP!</bullet> <bullet>If you have very time consuming functions in your code, consider writing them as C extensions</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-intro.xml +++ presentations/slides/php-best-practices/performance-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common mistakes to make your apps slow</bullet> <bullet>Some tips to boost performance by coding</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-mod_gzip.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-mod_gzip.xml +++ presentations/slides/php-best-practices/performance-mod_gzip.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - mod_gzip</title> <blurb>The issue: Too few bandwidth</blurb> <list> <bullet>Sometimes CPU power is not an issue</bullet> <bullet>With lots of large data or low bandwidth speed is low, too</bullet> <bullet>Usual performance tips do not help here</bullet> </list> <blurb>The solution: mod_gzip</blurb> <list> <bullet>Compresses your data on the fly</bullet> <bullet>GZIP compression is part of HTTP 1.1</bullet> <bullet>Can reduce the data to transfer up to 80%</bullet> <bullet>Available as an Apache module</bullet> </list> <blurb>http://sourceforge.net/projects/mod-gzip/</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-oo.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-oo.xml +++ presentations/slides/php-best-practices/performance-oo.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Keep OO within a limit</title> <blurb>The issue: PHP5 has cool OO features</blurb> <list> <bullet>OO is cool, but sometimes just overhead</bullet> <bullet>Each object consumes a lot of memory in PHP</bullet> <bullet>Each mezthod call consumes a lot of time in PHP</bullet> </list> <example results="0"><![CDATA[<?php class Integer { protected $value = 0; function __construct($int) { $this->value = $int; } } ?>]]></example> <blurb>Nice OO, but much too much overhead in PHP</blurb> <blurb>The solution: Knowing where the limits are</blurb> <list> <bullet>Do not implement every data structure as a class, arrays are useful, too</bullet> <bullet>Don't split methods too much, think, which code you will really re-use</bullet> <bullet>You can always split the code of a method later, when needed</bullet> <bullet>Do you really need a that deep class tree?</bullet> <bullet>Before applying a cool OO pattern, think if it really fits your case</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-opcodecache1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-opcodecache1.xml +++ presentations/slides/php-best-practices/performance-opcodecache1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - OP code caching - 1</title> <blurb>The issue: Compiling PHP code takes a lot of time</blurb> <list> <bullet>Your PHP code is recompiled on every request</bullet> <bullet>Even if it takes only 0.5 sec per request, this are more than 2 minutes for 250 requests</bullet> <bullet>Compiling a script takes sometimes longer than executing it</bullet> </list> <blurb>The solution: OP code caches</blurb> <list> <bullet>Zend engine compiles PHP code into OP codes before executing it</bullet> <bullet>The generated OP codes do not change until you change the script</bullet> <bullet>An OP code cache saves you from the compile step</bullet> </list> <blurb>Recommendation: OP code caches</blurb> <list> <bullet>APC (open source) http://pecl.php.net/APC</bullet> <bullet>Zend performance suite (commercial) http://zend.com</bullet> <bullet>mmCache (deprecated) http://turck-mmcache.sourceforge.net/</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-opcodecache2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-opcodecache2.xml +++ presentations/slides/php-best-practices/performance-opcodecache2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - OP code caching - 2</title> <image align="center" filename="opcache.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-profiling.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-profiling.xml +++ presentations/slides/php-best-practices/performance-profiling.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Profiling</title> <blurb>The issue: It's hard to find the bottleneck</blurb> <list> <bullet>Even best designed and coded apps maybe slow</bullet> <bullet>Finding the bottleneck is sometimes really hard</bullet> <bullet>Trial and error is time consuming</bullet> </list> <blurb>The solution: Profile your code</blurb> <list> <bullet>A profiler shows you, which parts of your code consumes how many time</bullet> <bullet>The Xdebug debugger already contains a profiler</bullet> <bullet>Profiling shows you the bottlenecks in overview</bullet> </list> <blurb>Recommendation: Profiler</blurb> <list> <bullet>Xdebug (open source) http://xdebug.org</bullet> <bullet>APD (open source) http://pecl.php.net/package/apd</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-regex.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-regex.xml +++ presentations/slides/php-best-practices/performance-regex.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Watch your regex</title> <blurb>The issue: Regex can consume a lot of time</blurb> <list> <bullet>Prefer over PCRE over EREG (much more powerful and faster!)</bullet> <bullet>Bad written regex can consume tons of time (backtracking)</bullet> <bullet>C implemented functions are always faster than regex</bullet> </list> <blurb>The solution: Think twice about each regex</blurb> <list> <bullet>Is there really need for a regex or does a PHP function do the trick?</bullet> <bullet>Replace all your EREGs with PCREs</bullet> <bullet>Try to avoid backtracking as much as possible (U modifier, if necessary)</bullet> <bullet>Reading recommendation: Mastering Regular Expressions (http://www.oreilly.com/catalog/regex/)</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-simple.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-simple.xml +++ presentations/slides/php-best-practices/performance-simple.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Simple enhancements</title> <blurb>The issue: Often used simple constructs can waste a valid amount of time</blurb> <list> <bullet>A main usage of webapplications is string processing.</bullet> <bullet>Look for the most often used constructs in your application</bullet> </list> <blurb>The solution: Simple optimizations can save a lot of time</blurb> <list> <bullet>Prefer ' over " and save a step of parsing.</bullet> </list> <example result="0"><![CDATA[<?php echo 'Hello\nworld.'; echo "Hello\nworld."; ?>]]></example> <list> <bullet>Use echo's multiple parameters instead of string concatenation.</bullet> </list> <example result="0"><![CDATA[<?php echo 'Hello', $world; echo 'Hello ' . $world; ?>]]></example> <list> <bullet>Always use ++$i instead of $i++</bullet> </list> <example result="0"><![CDATA[<?php for ($i = 0; $i < 1000; $i++); for ($i = 0; $i < 1000; ++$i); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/php-best-practices.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/php-best-practices.xml +++ presentations/slides/php-best-practices/php-best-practices.xml <?xml version="1.0" encoding="iso-8859-1"?> <presentation template="css" navmode="html" navbarbackground="#4373b4" navbartopiclinks="0" navColor="#f1fbff" logo1="" stylesheet="presentations/slides/perf/ezp-toby.css" backgroundfixed="1" > <topic>PHP</topic> <title>PHP best practices - The dos and don'ts</title> <event>Free and Open Source software Conference</event> <location>St. Augustin, Germany</location> <date>June 24th, 2006</date> <speaker>Tobias Schlitt & Kore Nordmann</speaker> <email>ts@ez.no & kn@ez.no</email> <!-- Intro --> <slide>slides/php-best-practices/title.xml</slide> <slide>slides/php-best-practices/aboutme-kore.xml</slide> <slide>slides/php-best-practices/aboutme-toby.xml</slide> <slide>slides/php-best-practices/agenda.xml</slide> <!-- About this talk --> <slide>slides/php-best-practices/about.xml</slide> <!-- General --> <slide>slides/php-best-practices/general-intro.xml</slide> <slide>slides/php-best-practices/general-agenda.xml</slide> <slide>slides/php-best-practices/general-typesafe1.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-shortopen.xml</slide> <slide>slides/php-best-practices/general-e_strict.xml</slide> <slide>slides/php-best-practices/general-exceptions.xml</slide> <!-- Security --> <slide>slides/php-best-practices/security-intro.xml</slide> <slide>slides/php-best-practices/security-agenda.xml</slide> <slide>slides/php-best-practices/security-variables-1.xml</slide> <slide>slides/php-best-practices/security-variables-2.xml</slide> <slide>slides/php-best-practices/security-sql.xml</slide> <slide>slides/php-best-practices/security-input.xml</slide> <slide>slides/php-best-practices/security-xss.xml</slide> <slide>slides/php-best-practices/security-obscurity.xml</slide> <slide>slides/php-best-practices/security-rights.xml</slide> <slide>slides/php-best-practices/security-configuration-1.xml</slide> <slide>slides/php-best-practices/security-configuration-2.xml</slide> <slide>slides/php-best-practices/security-cookies.xml</slide> <!-- Performance --> <slide>slides/php-best-practices/performance-intro.xml</slide> <slide>slides/php-best-practices/performance-agenda.xml</slide> <slide>slides/php-best-practices/performance-cvsphp.xml</slide> <slide>slides/php-best-practices/performance-simple.xml</slide> <slide>slides/php-best-practices/performance-caching1.xml</slide> <slide>slides/php-best-practices/performance-caching2.xml</slide> <slide>slides/php-best-practices/performance-regex.xml</slide> <slide>slides/php-best-practices/performance-opcodecache1.xml</slide> <slide>slides/php-best-practices/performance-opcodecache2.xml</slide> <slide>slides/php-best-practices/performance-profiling.xml</slide> <slide>slides/php-best-practices/performance-mod_gzip.xml</slide> <!-- High flexibility --> <slide>slides/php-best-practices/flexi-intro.xml</slide> <slide>slides/php-best-practices/flexi-agenda.xml</slide> </presentation> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-agenda.xml +++ presentations/slides/php-best-practices/security-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Agenda</title> <list> <bullet>Variable injection</bullet> <bullet>SQL injection</bullet> <bullet>Input filtering</bullet> <bullet>Output escaping</bullet> <bullet>Security by obscurity</bullet> <bullet>Fix the rights</bullet> <bullet>Configuration</bullet> <bullet>Cookies and Sessions</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-configuration-1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-configuration-1.xml +++ presentations/slides/php-best-practices/security-configuration-1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Configuration - 1</title> <blurb>The issue: Incorrect escaping in data storages and output.</blurb> <list> <bullet>Decreases performance of your complete application</bullet> <bullet>For proper escaping you need strip_slashes() and the storage specific function.</bullet> </list> <blurb>The solution: Turn off magic_quotes in production environment and escape properly.</blurb> <blurb>Undo magic_quotes.</blurb> <example result="0"><![CDATA[<?php if (get_magic_quotes_gpc()) { function strip_quotes(&$var) { if (is_array($var) { array_walk($var, 'strip_quotes'); } else { $var = stripslashes($var); } } // Handle GPC foreach (array('GET','POST','COOKIE') as $v) { if (!empty(${"_".$v})) { array_walk(${"_".$v}, 'strip_quotes'); } } } ?>]]></example> <blurb>Such recursive functions can easily be exploited - this will consume all of the servers memory and crash the script.</blurb> <example result="0"><![CDATA[<?php $qry = str_repeat('[]', 1024); file_get_contents('http://example.com/site.php?a' . $qry . '=1'); ?>]]></example> <blurb>Use the following faster and safer script.</blurb> <example result="0"><![CDATA[<?php if (get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE); while (list($k,$v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-configuration-2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-configuration-2.xml +++ presentations/slides/php-best-practices/security-configuration-2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Configuration - 2</title> <blurb>The issue: register_globals is still used in many applications and even for developing</blurb> <list> <bullet>Pollutes the global namespace.</bullet> <bullet>Can overwrite not properly initialized variables.</bullet> </list> <blurb>The solution: Turn off register_globals in development and production environments.</blurb> <list> <bullet>Workarounds could overwrite global variables before PHP 4.4.1 and PHP 5.0.5</bullet> <bullet>Still possible with own importing mechanisms.</bullet> <bullet>Fixed in extract() and import_request_variables().</bullet> </list> <blurb>register_globals and magic_quotes will be removen in PHP 6</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-cookies.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-cookies.xml +++ presentations/slides/php-best-practices/security-cookies.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Cookies and Sessions</title> <blurb>The issue: Cookies can easily be modified by users.</blurb> <list> <bullet>Do not store important information in cookies</bullet> <bullet>Can be faked very easily by automated scripts.</bullet> </list> <blurb>The solution: Use ext/session to store user data.</blurb> <list> <bullet>If available, a session ID will be stored in a cookie automatically.</bullet> <bullet>Data will be stored on the servers filesystem or database.</bullet> </list> <blurb>Hint: Never store passwords as clear text or too simple md5 hash.</blurb> <example result="1"><![CDATA[<?php function getPasswordHash($user, $password) { return md5('mySite' . $user . $password); } echo getPasswordHash('username', 'password'); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-input.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-input.xml +++ presentations/slides/php-best-practices/security-input.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Input validation</title> <blurb>The issue: Validating user input is a nasty task.</blurb> <blurb>The solution: use ext/filter oder ext/ctype</blurb> <example result="1"><![CDATA[<?php var_dump( ctype_alnum( 'foobar_42' ) ); var_dump( ctype_alnum( 'Bad Characters $%&/' ) ); var_dump(filter_data('bob@example.com', FILTER_VALIDATE_EMAIL)); var_dump(filter_data('example.com', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)); ]]></example> <blurb>Hint: For numeric IDs you can simply cast the variable to integer</blurb> <example result="1"><![CDATA[<?php var_dump( (int) '42' ); var_dump( (int) '42; DELETE * FROM users;' ); var_dump( (int) 'Evil string' ); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-intro.xml +++ presentations/slides/php-best-practices/security-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common pitfalls and their solution</bullet> <bullet>Paying attention on your user</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-obscurity.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-obscurity.xml +++ presentations/slides/php-best-practices/security-obscurity.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Security by obscurity</title> <blurb>The issue: Knowledge about paths and extensions makes it easier to exploit your system.</blurb> <list> <bullet>Obscurity can be just an additional feature of your security concept</bullet> </list> <blurb>The solution: Hide information</blurb> <list> <bullet>Never have phpinfo() in your webroot. It exposes information about pathes, extensions and configuration.</bullet> <bullet>Turn off display_errors in your production environment. - Use log_errors instead.</bullet> <bullet>Changing default filetypes and disabling expose_php may help, too.</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-permissions.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-permissions.xml +++ presentations/slides/php-best-practices/security-permissions.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Fix the permissions</title> <blurb>The issue: Wrong access permissions makes it easier to take over your webserver</blurb> <blurb>The solution: Fix your access rights</blurb> <list> <bullet>No writeable and excuteable files in your webroot.</bullet> <bullet>No writeable PHP files.</bullet> <bullet>Disallow external read access to files which contains classes, configuration or application code.</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-sql.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-sql.xml +++ presentations/slides/php-best-practices/security-sql.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - SQL injection</title> <blurb>The issue: Using userdata in queries often causes users manipulating queries.</blurb> <example result="0"><![CDATA[<?php $sql = 'SELECT password FROM user WHERE login = ' . $_GET['login']; ?> Request: http://example.com/tests/simple.php?login=username+OR+1 ]]></example> <blurb>The solution: Use databases extensions escape functions</blurb> <example result="0"><![CDATA[<?php $sql = 'SELECT password FROM user WHERE login = ' . mysql_real_escape_string( $_GET['login'] ); ?>]]></example> <blurb>Hint: Even better use prepared statements</blurb> <example result="0"><![CDATA[<?php $db = new PDO( ... ); $stmt = $db->prepare( 'SELECT password FROM user WHERE login = ?' ); $stmt->execute( array( $_GET['login'] ) ); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-variables_1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-variables_1.xml +++ presentations/slides/php-best-practices/security-variables_1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Variable injection - 1</title> <blurb>The issue: Unintialized variables can lead for unexpected code segments to be executed.</blurb> <example result="0"><![CDATA[<?php if (correct_user($_POST['user'], $_POST['password']) { $login = true; } if ($login) { forward_to_secure_environment(); } ?>]]></example> <blurb>The solution: Initialize your variables</blurb> <list> <bullet>Never trust ANY user input.</bullet> </list> <blurb>Common XSS example: This request will open an JavaScript alert window with text "XSS".</blurb> <example result="0"><![CDATA[ <form action="<?php echo $_SERVER['PHP_SELF']; ?>"> </form> Request: http://example.com/tests/simple.php/%22%3E%3Cscript%3Ealert('xss')%3C/script%3E%3Cfoo ]]></example> <blurb>Variables containing user input: $_POST, $_GET, $_REQUEST, $_COOKIE, $_SERVER, ($_ENV)</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-variables_2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-variables_2.xml +++ presentations/slides/php-best-practices/security-variables_2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Variable injection - 2</title> <blurb>The issue: Variables in include statements can lead to execution of external code</blurb> <list> <bullet>With allow_url_fopen = On (default) external code can be included</bullet> </list> <example result="0"><![CDATA[<?php require_once $_GET['action'] . '.php'; ?>]]></example> <blurb>The solution: Validate included files against a whitelist using arrays or switch statements.</blurb> <example result="0"><![CDATA[<?php $files = array( 'show' => 'show.php', 'list' => 'list.php', ); if (isset($files[$_GET['action']])) { require_once $files[$_GET['action']]; } else { echo 'Not a valid action.'; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-xss.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-xss.xml +++ presentations/slides/php-best-practices/security-xss.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Output escaping</title> <blurb>The issue: Cross site scripting attacks caused by inproper escaping.</blurb> <list> <bullet>Every user input may contain characters which will be interpreted by the displaying programm.</bullet> </list> <example result="1"><![CDATA[<?php $text = '<b>Hallo</b> Welt.'; echo $text; echo htmlentities( $text ); ?>]]></example> <blurb>The solution: Use escape functions on output</blurb> <list> <bullet>Remember, that database content may be user input to.</bullet> </list> <blurb>Hint: Consider the context of output, or use a template system which automatically takes care of output escaping</blurb> <example result="0"><![CDATA[<?php $config = ezcTemplateConfiguration::getInstance(); $config->context = new ezcTemplateXhtmlContext(); $t = new ezcTemplate(); $t->process( "hello_world.ezt" ); ?>]]></example> <blurb>In eZ Template variables are escaped according to the context of the output</blurb> <example result="0"><![CDATA[ {var $myVar = '<b>Hello world!</b>'} {$myVar} ]]></example> <blurb>To not escape the content of the var, you need to call raw explicitely</blurb> <example result="0"><![CDATA[ {var $myVar = '<b>Hello world!</b>'} {raw $myVar} ]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/talk.css?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/talk.css +++ presentations/slides/php-best-practices/talk.css <style title="Default" type="text/css"> body { font-size: 10pt; margin-left:290px; margin-right:0em; margin-bottom:0em; background-image: url(presentations/slides/perf/ezp.png); background-attachment: fixed; background-repeat: no-repeat; font-family: verdana, tahoma, arial, helvetica, sans-serif; overflow: -moz-scrollbars-none; } div.sticky { margin: 0; position: fixed; top: 0em; left: 290px; right: auto; bottom: auto; } div.navbar { padding: 4; margin: 0; height: 14em; font-family: verdana, tahoma, arial, helvetica, sans-serif; z-index: 99; } div.navbar_title, div.navbar_title a, div.subtitle { font-size: 32px; color: #698fe5; text-decoration: none; text-align: left; font-weight: bold; margin-top: 20px; } div.subtitle { margin-top: 5px; font-size: 24; font-weight: normal; font-style: italic; } div.navbar_nr a { font-size: 16px; color: #77a; text-decoration: none; position: fixed; right: 10px; bottom: 0px; } div.mainarea { margin-top: 120px; top: 150px; width: 733px; height: 600px; overflow: auto; overflow: -moz-scrollbars-vertical; } ul.pres { list-style: circle; font-size: 20pt; } ul.level2 { list-style: circle; font-size: 20pt; margin-left: 40px; margin-top: -15px; } li.pres_bullet { font-size: 20pt; margin-right: 40px; } li.pres_bullet_nr { font-size: 28pt; margin-right: 40px; list-style-type: decimal; } ul.large div li.pres_bullet { font-size: 40pt; } ul.small div li.pres_bullet { font-size: 20pt; } div.title_blurb { font-size: 80px; text-align: center; font-weight: bold; } div.small_blurb { font-size: 24px; } div.blurb, div.bit_larger_output_text { font-size: 20pt; width: 100%; } div.bit_larger_output_text { margin-top: 10px; } div.x_small_blurb { font-size: 0.5em; } div.large_blurb { font-size: 32pt; } div.large_blurb_center { font-size: 48px; text-align: center; } div.quote { font-size: 48px; text-align: center; margin-left: 40px; margin-right: 40px; } div.quote_attr { font-size: 32px; text-align: right; margin-right: 40px; } div.xx_large_blurb_center { font-size: 80px; text-align: center; } div.q_mark { text-align: center; font-size: 480px; } div.shadow, code { font-size: 18px; width: 640px; } div.example code, div.highlight code, div.bit_larger, div.bit_larger code, div.bit_larger_output { background: #eee; font-size: 23px; width: 100%; } div.example, div.highlight, div.bit_larger, div.bit_larger_output { margin-left: 20px; margin-right: 20px; } div.large code, div.large { font-size: 32px; background: #eee; font-weight: bold; margin-left: 20px; margin-right: 20px; } div.highlight code, div.highlight { background: #fffc00; font-weight: bold; } div.code_small, div.code_medium, div.code_large, div.example { background: #eee; } div.code_small code { font-size: 12px; } div.code_medium code, div.code_medium pre { font-size: 20px; } div.code_large code, div.code_large pre { font-size: 24px; } div.example pre { font-size: 23px; } div.event, div.event-date, div.event-presenter { text-align: center; font-size: 32pt; } div.pres-url-small { text-align: center; font-size: 24pt; } img.spaced { margin-right: 25px; margin-left: 25px; margin-top: 25px; margin-bottom: 25px; } table { font-size: 20pt; } </style> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/thanks.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/thanks.xml +++ presentations/slides/php-best-practices/thanks.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="Thank you for listening"> <list> <bullet>I hope you like eZ components!</bullet> <bullet>I hope you learned what you expected!</bullet> </list> <break /> <break /> <list> <bullet>Thank you for inviting me!</bullet> <bullet>It's been a great pleasure to be here!</bullet> </list> <break /> <break /> <blurb> Further questions? </blurb> <list> <bullet>http://ez.no/community/forum/ez_components</bullet> <bullet>Tobias Schlitt <ts@ez.no></bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/title.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/title.xml +++ presentations/slides/php-best-practices/title.xml <slide fontsize="3.5em"> <title>Welcome!</title> <break lines="3"/> <blurb class="event">PHP best practices</blurb> <break/> <blurb class="event">The dos and don'ts</blurb> <break/> <blurb class="event-date">FrOSCon, St. Augustin, Germany</blurb> <break/> <blurb class="event-presenter">Kore Nordmann - &lt;kn@ez.no&gt;</blurb> <break/> <blurb class="event-presenter">Tobias Schlitt - &lt;ts@ez.no&gt;</blurb> </slide>
http://cvs.php.net/viewvc.cgi/presentations/php-best-practices.xml?view=markup&rev=1.1 Index: presentations/php-best-practices.xml +++ presentations/php-best-practices.xml <?xml version="1.0" encoding="iso-8859-1"?> <presentation template="css" navmode="html" navbarbackground="#4373b4" navbartopiclinks="0" navColor="#f1fbff" logo1="" stylesheet="presentations/slides/php-best-practices/talk.css" backgroundfixed="1" > <topic>PHP</topic> <title>PHP best practices - The dos and don'ts</title> <event>Free and Open Source software Conference</event> <location>St. Augustin, Germany</location> <date>June 24th, 2006</date> <speaker>Tobias Schlitt & Kore Nordmann</speaker> <email>ts@ez.no & kn@ez.no</email> <!-- Intro --> <slide>slides/php-best-practices/title.xml</slide> <slide>slides/php-best-practices/aboutme-kore.xml</slide> <slide>slides/php-best-practices/aboutme-toby.xml</slide> <slide>slides/php-best-practices/agenda.xml</slide> <!-- About this talk --> <slide>slides/php-best-practices/about.xml</slide> <!-- General --> <slide>slides/php-best-practices/general-intro.xml</slide> <slide>slides/php-best-practices/general-agenda.xml</slide> <slide>slides/php-best-practices/general-typesafe1.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-shortopen.xml</slide> <slide>slides/php-best-practices/general-e_strict.xml</slide> <slide>slides/php-best-practices/general-exceptions.xml</slide> <slide>slides/php-best-practices/general-debugging1.xml</slide> <slide>slides/php-best-practices/general-debugging2.xml</slide> <slide>slides/php-best-practices/general-codingstandard.xml</slide> <slide>slides/php-best-practices/general-documentation.xml</slide> <!-- Security --> <slide>slides/php-best-practices/security-intro.xml</slide> <slide>slides/php-best-practices/security-agenda.xml</slide> <slide>slides/php-best-practices/security-variables_1.xml</slide> <slide>slides/php-best-practices/security-variables_2.xml</slide> <slide>slides/php-best-practices/security-sql.xml</slide> <slide>slides/php-best-practices/security-input.xml</slide> <slide>slides/php-best-practices/security-xss.xml</slide> <slide>slides/php-best-practices/security-obscurity.xml</slide> <slide>slides/php-best-practices/security-permissions.xml</slide> <slide>slides/php-best-practices/security-configuration-1.xml</slide> <slide>slides/php-best-practices/security-configuration-2.xml</slide> <slide>slides/php-best-practices/security-cookies.xml</slide> <!-- Performance --> <slide>slides/php-best-practices/performance-intro.xml</slide> <slide>slides/php-best-practices/performance-agenda.xml</slide> <slide>slides/php-best-practices/performance-cvsphp.xml</slide> <slide>slides/php-best-practices/performance-simple.xml</slide> <slide>slides/php-best-practices/performance-oo.xml</slide> <slide>slides/php-best-practices/performance-caching1.xml</slide> <slide>slides/php-best-practices/performance-caching2.xml</slide> <slide>slides/php-best-practices/performance-regex.xml</slide> <slide>slides/php-best-practices/performance-opcodecache1.xml</slide> <slide>slides/php-best-practices/performance-opcodecache2.xml</slide> <slide>slides/php-best-practices/performance-profiling.xml</slide> <slide>slides/php-best-practices/performance-mod_gzip.xml</slide> <!-- Open part --> <slide>slides/php-best-practices/open-intro.xml</slide> <slide>slides/php-best-practices/end.xml</slide> </presentation> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/about.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/about.xml +++ presentations/slides/php-best-practices/about.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>About this talk</title> <blurb>Why should you attend this talk?</blurb> <list> <bullet>PHP is easy to learn, but hard to master</bullet> <bullet>Security issues are lurking everywhere</bullet> <bullet>Performance is important, especially for a scripting language</bullet> <bullet>Open source should be "nice looking"</bullet> </list> <blurb>What will I learn here?</blurb> <list> <bullet>A lot of common mistakes so you can avoid them</bullet> <bullet>A lot of common tricks you can use</bullet> <bullet>Some nice tools to make your work more easy and secure</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/aboutme-kore.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/aboutme-kore.xml +++ presentations/slides/php-best-practices/aboutme-kore.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="About us - Kore"> <list> <bullet>Kore Nordmann <kn@ez.no></bullet> <bullet>Studies computer science at the university of Dortmund</bullet> <bullet>Working for eZ systems on the eZ components</bullet> <bullet>Member of the PEAR project</bullet> <bullet>PHP Usergroup Dortmund</bullet> </list> <break /> <break /> <list> <bullet>http://ez.no</bullet> <bullet>http://kore-nordmann.de</bullet> <bullet>http://phpugdo.de</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/aboutme-toby.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/aboutme-toby.xml +++ presentations/slides/php-best-practices/aboutme-toby.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="About us - Toby"> <list> <bullet>Tobias Schlitt <ts@ez.no></bullet> <bullet>IT specialist, currently studying computer science</bullet> <bullet>Working for eZ systems on the eZ components</bullet> <bullet>Member of the PEAR project</bullet> <bullet>PHP Usergroup Dortmund</bullet> </list> <break /> <break /> <list> <bullet>http://ez.no</bullet> <bullet>http://schlitt.info</bullet> <bullet>http://phpugdo.de</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/agenda.xml +++ presentations/slides/php-best-practices/agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="6em"> <title>Agenda</title> <list> <bullet>About this talk</bullet> <bullet>General dos and don'ts</bullet> <bullet>Security</bullet> <bullet>Performance</bullet> <bullet>Open part</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/end.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/end.xml +++ presentations/slides/php-best-practices/end.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>The end</title> <blurb>Thanks for listening!</blurb> <blurb>We hope you...</blurb> <list> <bullet>... learned what you hoped to learn</bullet> <bullet>... code better PHP now</bullet> <bullet>... possibly slept well ;)</bullet> </list> <blurb>This slides online:</blurb> <list> <bullet>http://talks.php.net</bullet> </list> <blurb>Reaching us:</blurb> <list> <bullet>Kore Nordmann <kn@ez.no></bullet> <bullet>Tobias Schlitt <ts@ez.no></bullet> </list> <blurb>Some important websites:</blurb> <list> <bullet>http://hardened-php.net</bullet> <bullet>http://planet-php.net</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-agenda.xml +++ presentations/slides/php-best-practices/general-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Agenda</title> <list> <bullet>Type safe coding</bullet> <bullet>Bad short open tags</bullet> <bullet>Being E_STRICT</bullet> <bullet>Exceptions</bullet> <bullet>Using a debugger</bullet> <bullet>Avoid reinventing the wheel</bullet> <bullet>Why coding standards are good</bullet> <bullet>Documentation</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-codingstandard.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-codingstandard.xml +++ presentations/slides/php-best-practices/general-codingstandard.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Codingstandard</title> <blurb>The issue: "I code like I want to!"</blurb> <list> <bullet>Other people have difficulties to read the code (open source)</bullet> <bullet>Maybe someone needs to take over maintainance of your code</bullet> <bullet>You might stumble yourself over it once upon a time</bullet> </list> <blurb>The solution: Coding standards</blurb> <list> <bullet>PEAR http://pear.php.net/manual/en/standards.php</bullet> <bullet>eZ systems http://ez.no/products/ez_publish/documentation/development/standards/php</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-debugging1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-debugging1.xml +++ presentations/slides/php-best-practices/general-debugging1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Using a debugger - 1</title> <blurb>The issue: "I don't need a debugger".</blurb> <list> <bullet>"var_dump(), print_r() and echo also do the job!"</bullet> <bullet>PHPs error messages are quite useless</bullet> <bullet>A debugger has some really neat features that save time and headache</bullet> </list> <example result="0"><![CDATA[<?php function foo() { phpinfo("bar"); } foo(); ?>]]></example> <blurb>Looks in plain PHP like this</blurb> <image align="center" filename="error_plain.png" pdf-scale="0.7"/> <blurb>Looks with a good debugger like this</blurb> <image align="center" filename="error_xdebug.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-debugging2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-debugging2.xml +++ presentations/slides/php-best-practices/general-debugging2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Using a debugger - 2</title> <blurb>The solution: Use a good debugger!</blurb> <blurb>Recommendation: Xdebug (http://xdebug.org)</blurb> <list> <bullet>Open source</bullet> <bullet>Wide spreaded and used</bullet> <bullet>Integrates as a PHP extension</bullet> <bullet>Integration with IDEs (like Comodo)</bullet> <bullet>Support for profiling and code-coverage analysis</bullet> </list> <blurb>Some other debuggers:</blurb> <list> <bullet>DBG http://dd.cron.ru/</bullet> <bullet>APD http://apd.communityconnect.com/</bullet> <bullet>Zend IDE (commercial) http://zend.com</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-documentation.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-documentation.xml +++ presentations/slides/php-best-practices/general-documentation.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Documentation</title> <blurb>The issue: Documentation is the most boring work</blurb> <list> <bullet>Re-read your code 6 month after you wrote it!</bullet> <bullet>Think about people who have to use your code</bullet> </list> <blurb>The solution: phpDocumentor</blurb> <list> <bullet>Implementation of JavaDoc for PHP</bullet> <bullet>Community accepted standard</bullet> <bullet>Avaiable through PEAR</bullet> <bullet>Allows auto-generation of API docs</bullet> <bullet>Also works for tutorials</bullet> <bullet>http://phpdoc.org</bullet> </list> <blurb>Useful hints</blurb> <list> <bullet>Write docs before implementing the code!</bullet> <bullet>You will probably not do it, if you do the other way around</bullet> <bullet>Document pedantically, fixing docs later sucks!</bullet> <bullet>Get used to update the docs, as soon as you change the code</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-e_strict.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-e_strict.xml +++ presentations/slides/php-best-practices/general-e_strict.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Being E_STRICT</title> <blurb>The issue: PHP has a new error level E_STRICT, since PHP 5.0.</blurb> <list> <bullet>E_STRICT forces you to code clean PHP 5 code</bullet> <bullet>Current E_STRICT will most probably become E_FATAL in PHP 6.0</bullet> <bullet>The resolution: Switch E_STRICT on and check your code</bullet> </list> <example result="0"><![CDATA[error_reporting=E_ALL | E_STRICT]]></example> <blurb>Typical E_STRICT error - Usage of outdated is_a() function</blurb> <example result="0"><![CDATA[<?php if ( is_a( $object, 'ClassName' ) ) { $object->foo(); } ?>]]></example> <blurb>Should be now</blurb> <example result="0"><![CDATA[<?php if ( $object instanceof ClassName ) { $object->foo(); } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-exceptions.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-exceptions.xml +++ presentations/slides/php-best-practices/general-exceptions.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Exceptions</title> <blurb>The issue: PHP has exceptions now, cool but dangerous.</blurb> <list> <bullet>Exceptions are a great tool for handling exceptional states</bullet> <bullet>Exceptions are often misused and become regulars</bullet> <bullet>Exceptions may make PHP leaking</bullet> </list> <example result="0"><![CDATA[<?php function foo() { if ($user_input !== "Hello!") { throw new Exception("User input wrong"); } } ?>]]></example> <blurb>Only use exceptions, when your application ends up in an exceptional state</blurb> <example result="0"><![CDATA[<?php function bar() { if (connection_timedout()) { throw new Exception("Connection timeout"); } } ?>]]></example> <blurb>Exceptions leak a little bit of memory when thrown e.g. out of for loops</blurb> <example result="0"><![CDATA[<?php foreach ($i = 1000000; $i > 0; $i--) { throw new Exceptions("Hehe, I'm leaking"); } ?>]]></example> <blurb>Allocated memory from the for-loop-header is not freeed correctly.</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-intro.xml +++ presentations/slides/php-best-practices/general-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common good manners for coding PHP</bullet> <bullet>Nice tips for clean PHP code</bullet> <bullet>Behaviours to avoid common mistakes</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-reinventwheel.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-reinventwheel.xml +++ presentations/slides/php-best-practices/general-reinventwheel.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Do not reinvent the wheel</title> <blurb>The issue: "I code everything on my own!"</blurb> <list> <bullet>Some people really code everything themselves</bullet> <bullet>This costs time and causes headache</bullet> <bullet>Errors occur more often in 1-maintained code</bullet> </list> <blurb>The solution: Access libraries like...</blurb> <list> <bullet>eZ components http://ez.no/products/ez_components</bullet> <bullet>Zend Framework http://framework.zend.com/</bullet> <bullet>PEAR http://pear.php.net/</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-shortopen.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-shortopen.xml +++ presentations/slides/php-best-practices/general-shortopen.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Bad short open tags</title> <blurb>The issue: PHP allows several open tags beside <![CDATA["<?php"]]>.</blurb> <example result="0"><![CDATA[<? echo "Hello world"; ?>]]></example> <blurb>Or, even worse.</blurb> <example result="0"><![CDATA[<?="Hello world"; ?>]]></example> <blurb>Or worst:</blurb> <example result="0"><![CDATA[<% echo "Hello world"; %>]]></example> <list> <bullet><![CDATA[<?]]> on its own is reserved for XML declaration</bullet> <bullet><![CDATA[<?=]]> is complete invalid XML</bullet> <bullet><![CDATA[<%]]> is ASP style and sucks</bullet> <bullet>All styles beside the official <![CDATA[<?php ... ?>]]> are deprecated</bullet> </list> <blurb>The solution: Stick to standard tags and convert all your scripts!</blurb> <list> <bullet>Guaranteed to be supported further</bullet> <bullet>Represents a valid XML processing instruction</bullet> <bullet>Unique in all PHP documents</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-typesafe1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-typesafe1.xml +++ presentations/slides/php-best-practices/general-typesafe1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Type safe coding - 1</title> <blurb>The issue: In general PHP is loosely typed.</blurb> <example result="1"><![CDATA[<?php $foo = "1"; $bar = $foo + 1; var_dump($foo, $bar); ?>]]></example> <blurb>The normal comparison operators are loosely typed, too.</blurb> <example result="1"><![CDATA[<?php $int = 1; $string = "1"; $bool = true; var_dump($int == $string); var_dump($string == $bool); var_dump($int == $bool); ?>]]></example> <blurb>This can cause WTF situations</blurb> <example result="1"><![CDATA[<?php var_dump( '1' == '1.' ); ?>]]></example> <blurb>This may lead to very common mistakes:</blurb> <example result="1"><![CDATA[<?php function foo($answer) { if ($answer > 10) { return true; } else { return $answer; } } if (foo(11)) { echo "11 is greater 10<br />"; } if (foo(9)) { echo "9 is greater than 10<br />"; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/general-typesafe2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/general-typesafe2.xml +++ presentations/slides/php-best-practices/general-typesafe2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Type safe coding - 2</title> <blurb>The solution: Type safe coding.</blurb> <example result="1"><![CDATA[<?php $foo = "1"; $bar = (int)$foo + 1; var_dump((int)$foo, $bar); ?>]]></example> <blurb>Use the type safe comparison operators.</blurb> <example result="1"><![CDATA[<?php $int = 1; $string = "1"; $bool = true; var_dump($int === $string); var_dump($string === $bool); var_dump($int === $bool); ?>]]></example> <blurb>The shown mistake is gone:</blurb> <example result="1"><![CDATA[<?php function foo($answer) { if ($answer > 10) { return true; } else { return $answer; } } if (foo(11) === true) { echo "11 is greater 10<br />"; } if (foo(9) === true) { echo "9 is greater than 10<br />"; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/open-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/open-intro.xml +++ presentations/slides/php-best-practices/open-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Open part</title> <blurb>Now it is time for...</blurb> <list> <bullet>Discussion</bullet> <bullet>Questions and answers</bullet> <bullet>Critics</bullet> <bullet>Chatting</bullet> <bullet>...</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-agenda.xml +++ presentations/slides/php-best-practices/performance-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Agenda</title> <list> <bullet>Prefer C over PHP</bullet> <bullet>Simple speed enhancements</bullet> <bullet>Keep OO within a limit</bullet> <bullet>Cache as much as possible</bullet> <bullet>Watch your regex</bullet> <bullet>OP code caching</bullet> <bullet>Profiling</bullet> <bullet>mod_gzip</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-caching1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-caching1.xml +++ presentations/slides/php-best-practices/performance-caching1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Caching - 1</title> <blurb>The issue: Most content is not dynamic content!</blurb> <list> <bullet>90% of the time your website generates the same data again</bullet> <bullet>Each requests results in the same database results</bullet> <bullet>90% of the performance of your server is to perform useles work</bullet> </list> <blurb>The solution: Caching, caching, caching</blurb> <list> <bullet>Think how often your content (or pieces of it) is regenerated</bullet> <bullet>Cache it in between!</bullet> <bullet>Think about publishing based caching</bullet> </list> <blurb>Good caching classes</blurb> <list> <bullet>eZ Cache (http://ez.no/products/ez_components)</bullet> <bullet>Cache_Lite (http://pear.php.net/Cache_Lite</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-caching2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-caching2.xml +++ presentations/slides/php-best-practices/performance-caching2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Caching - 2</title> <image align="center" filename="caching.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-cvsphp.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-cvsphp.xml +++ presentations/slides/php-best-practices/performance-cvsphp.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - C versus PHP</title> <blurb>The issue: PHP functions are faster than userland functions</blurb> <list> <bullet>PHP internal functions save a lot of time</bullet> <bullet>Still users tend to write the most basic functions in userland</bullet> </list> <blurb>The solution: Read the manual!</blurb> <list> <bullet>PHP has wonderful docs! Learn to love them!</bullet> <bullet>Before implementing a basic function on your own, check if it exists in PHP!</bullet> <bullet>If you have very time consuming functions in your code, consider writing them as C extensions</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-intro.xml +++ presentations/slides/php-best-practices/performance-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common mistakes to make your apps slow</bullet> <bullet>Some tips to boost performance by coding</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-mod_gzip.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-mod_gzip.xml +++ presentations/slides/php-best-practices/performance-mod_gzip.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - mod_gzip</title> <blurb>The issue: Too few bandwidth</blurb> <list> <bullet>Sometimes CPU power is not an issue</bullet> <bullet>With lots of large data or low bandwidth speed is low, too</bullet> <bullet>Usual performance tips do not help here</bullet> </list> <blurb>The solution: mod_gzip</blurb> <list> <bullet>Compresses your data on the fly</bullet> <bullet>GZIP compression is part of HTTP 1.1</bullet> <bullet>Can reduce the data to transfer up to 80%</bullet> <bullet>Available as an Apache module</bullet> </list> <blurb>http://sourceforge.net/projects/mod-gzip/</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-oo.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-oo.xml +++ presentations/slides/php-best-practices/performance-oo.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Keep OO within a limit</title> <blurb>The issue: PHP5 has cool OO features</blurb> <list> <bullet>OO is cool, but sometimes just overhead</bullet> <bullet>Each object consumes a lot of memory in PHP</bullet> <bullet>Each mezthod call consumes a lot of time in PHP</bullet> </list> <example results="0"><![CDATA[<?php class Integer { protected $value = 0; function __construct($int) { $this->value = $int; } } ?>]]></example> <blurb>Nice OO, but much too much overhead in PHP</blurb> <blurb>The solution: Knowing where the limits are</blurb> <list> <bullet>Do not implement every data structure as a class, arrays are useful, too</bullet> <bullet>Don't split methods too much, think, which code you will really re-use</bullet> <bullet>You can always split the code of a method later, when needed</bullet> <bullet>Do you really need a that deep class tree?</bullet> <bullet>Before applying a cool OO pattern, think if it really fits your case</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-opcodecache1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-opcodecache1.xml +++ presentations/slides/php-best-practices/performance-opcodecache1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - OP code caching - 1</title> <blurb>The issue: Compiling PHP code takes a lot of time</blurb> <list> <bullet>Your PHP code is recompiled on every request</bullet> <bullet>Even if it takes only 0.5 sec per request, this are more than 2 minutes for 250 requests</bullet> <bullet>Compiling a script takes sometimes longer than executing it</bullet> </list> <blurb>The solution: OP code caches</blurb> <list> <bullet>Zend engine compiles PHP code into OP codes before executing it</bullet> <bullet>The generated OP codes do not change until you change the script</bullet> <bullet>An OP code cache saves you from the compile step</bullet> </list> <blurb>Recommendation: OP code caches</blurb> <list> <bullet>APC (open source) http://pecl.php.net/APC</bullet> <bullet>Zend performance suite (commercial) http://zend.com</bullet> <bullet>mmCache (deprecated) http://turck-mmcache.sourceforge.net/</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-opcodecache2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-opcodecache2.xml +++ presentations/slides/php-best-practices/performance-opcodecache2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - OP code caching - 2</title> <image align="center" filename="opcache.png" pdf-scale="0.7"/> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-profiling.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-profiling.xml +++ presentations/slides/php-best-practices/performance-profiling.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Profiling</title> <blurb>The issue: It's hard to find the bottleneck</blurb> <list> <bullet>Even best designed and coded apps maybe slow</bullet> <bullet>Finding the bottleneck is sometimes really hard</bullet> <bullet>Trial and error is time consuming</bullet> </list> <blurb>The solution: Profile your code</blurb> <list> <bullet>A profiler shows you, which parts of your code consumes how many time</bullet> <bullet>The Xdebug debugger already contains a profiler</bullet> <bullet>Profiling shows you the bottlenecks in overview</bullet> </list> <blurb>Recommendation: Profiler</blurb> <list> <bullet>Xdebug (open source) http://xdebug.org</bullet> <bullet>APD (open source) http://pecl.php.net/package/apd</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-regex.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-regex.xml +++ presentations/slides/php-best-practices/performance-regex.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Performance - Watch your regex</title> <blurb>The issue: Regex can consume a lot of time</blurb> <list> <bullet>Prefer over PCRE over EREG (much more powerful and faster!)</bullet> <bullet>Bad written regex can consume tons of time (backtracking)</bullet> <bullet>C implemented functions are always faster than regex</bullet> </list> <blurb>The solution: Think twice about each regex</blurb> <list> <bullet>Is there really need for a regex or does a PHP function do the trick?</bullet> <bullet>Replace all your EREGs with PCREs</bullet> <bullet>Try to avoid backtracking as much as possible (U modifier, if necessary)</bullet> <bullet>Reading recommendation: Mastering Regular Expressions (http://www.oreilly.com/catalog/regex/)</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/performance-simple.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/performance-simple.xml +++ presentations/slides/php-best-practices/performance-simple.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>General - Simple enhancements</title> <blurb>The issue: Often used simple constructs can waste a valid amount of time</blurb> <list> <bullet>A main usage of webapplications is string processing.</bullet> <bullet>Look for the most often used constructs in your application</bullet> </list> <blurb>The solution: Simple optimizations can save a lot of time</blurb> <list> <bullet>Prefer ' over " and save a step of parsing.</bullet> </list> <example result="0"><![CDATA[<?php echo 'Hello\nworld.'; echo "Hello\nworld."; ?>]]></example> <list> <bullet>Use echo's multiple parameters instead of string concatenation.</bullet> </list> <example result="0"><![CDATA[<?php echo 'Hello', $world; echo 'Hello ' . $world; ?>]]></example> <list> <bullet>Always use ++$i instead of $i++</bullet> </list> <example result="0"><![CDATA[<?php for ($i = 0; $i < 1000; $i++); for ($i = 0; $i < 1000; ++$i); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/php-best-practices.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/php-best-practices.xml +++ presentations/slides/php-best-practices/php-best-practices.xml <?xml version="1.0" encoding="iso-8859-1"?> <presentation template="css" navmode="html" navbarbackground="#4373b4" navbartopiclinks="0" navColor="#f1fbff" logo1="" stylesheet="presentations/slides/perf/ezp-toby.css" backgroundfixed="1" > <topic>PHP</topic> <title>PHP best practices - The dos and don'ts</title> <event>Free and Open Source software Conference</event> <location>St. Augustin, Germany</location> <date>June 24th, 2006</date> <speaker>Tobias Schlitt & Kore Nordmann</speaker> <email>ts@ez.no & kn@ez.no</email> <!-- Intro --> <slide>slides/php-best-practices/title.xml</slide> <slide>slides/php-best-practices/aboutme-kore.xml</slide> <slide>slides/php-best-practices/aboutme-toby.xml</slide> <slide>slides/php-best-practices/agenda.xml</slide> <!-- About this talk --> <slide>slides/php-best-practices/about.xml</slide> <!-- General --> <slide>slides/php-best-practices/general-intro.xml</slide> <slide>slides/php-best-practices/general-agenda.xml</slide> <slide>slides/php-best-practices/general-typesafe1.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-typesafe2.xml</slide> <slide>slides/php-best-practices/general-shortopen.xml</slide> <slide>slides/php-best-practices/general-e_strict.xml</slide> <slide>slides/php-best-practices/general-exceptions.xml</slide> <!-- Security --> <slide>slides/php-best-practices/security-intro.xml</slide> <slide>slides/php-best-practices/security-agenda.xml</slide> <slide>slides/php-best-practices/security-variables-1.xml</slide> <slide>slides/php-best-practices/security-variables-2.xml</slide> <slide>slides/php-best-practices/security-sql.xml</slide> <slide>slides/php-best-practices/security-input.xml</slide> <slide>slides/php-best-practices/security-xss.xml</slide> <slide>slides/php-best-practices/security-obscurity.xml</slide> <slide>slides/php-best-practices/security-rights.xml</slide> <slide>slides/php-best-practices/security-configuration-1.xml</slide> <slide>slides/php-best-practices/security-configuration-2.xml</slide> <slide>slides/php-best-practices/security-cookies.xml</slide> <!-- Performance --> <slide>slides/php-best-practices/performance-intro.xml</slide> <slide>slides/php-best-practices/performance-agenda.xml</slide> <slide>slides/php-best-practices/performance-cvsphp.xml</slide> <slide>slides/php-best-practices/performance-simple.xml</slide> <slide>slides/php-best-practices/performance-caching1.xml</slide> <slide>slides/php-best-practices/performance-caching2.xml</slide> <slide>slides/php-best-practices/performance-regex.xml</slide> <slide>slides/php-best-practices/performance-opcodecache1.xml</slide> <slide>slides/php-best-practices/performance-opcodecache2.xml</slide> <slide>slides/php-best-practices/performance-profiling.xml</slide> <slide>slides/php-best-practices/performance-mod_gzip.xml</slide> <!-- High flexibility --> <slide>slides/php-best-practices/flexi-intro.xml</slide> <slide>slides/php-best-practices/flexi-agenda.xml</slide> </presentation> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-agenda.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-agenda.xml +++ presentations/slides/php-best-practices/security-agenda.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Agenda</title> <list> <bullet>Variable injection</bullet> <bullet>SQL injection</bullet> <bullet>Input filtering</bullet> <bullet>Output escaping</bullet> <bullet>Security by obscurity</bullet> <bullet>Fix the rights</bullet> <bullet>Configuration</bullet> <bullet>Cookies and Sessions</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-configuration-1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-configuration-1.xml +++ presentations/slides/php-best-practices/security-configuration-1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Configuration - 1</title> <blurb>The issue: Incorrect escaping in data storages and output.</blurb> <list> <bullet>Decreases performance of your complete application</bullet> <bullet>For proper escaping you need strip_slashes() and the storage specific function.</bullet> </list> <blurb>The solution: Turn off magic_quotes in production environment and escape properly.</blurb> <blurb>Undo magic_quotes.</blurb> <example result="0"><![CDATA[<?php if (get_magic_quotes_gpc()) { function strip_quotes(&$var) { if (is_array($var) { array_walk($var, 'strip_quotes'); } else { $var = stripslashes($var); } } // Handle GPC foreach (array('GET','POST','COOKIE') as $v) { if (!empty(${"_".$v})) { array_walk(${"_".$v}, 'strip_quotes'); } } } ?>]]></example> <blurb>Such recursive functions can easily be exploited - this will consume all of the servers memory and crash the script.</blurb> <example result="0"><![CDATA[<?php $qry = str_repeat('[]', 1024); file_get_contents('http://example.com/site.php?a' . $qry . '=1'); ?>]]></example> <blurb>Use the following faster and safer script.</blurb> <example result="0"><![CDATA[<?php if (get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE); while (list($k,$v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-configuration-2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-configuration-2.xml +++ presentations/slides/php-best-practices/security-configuration-2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Configuration - 2</title> <blurb>The issue: register_globals is still used in many applications and even for developing</blurb> <list> <bullet>Pollutes the global namespace.</bullet> <bullet>Can overwrite not properly initialized variables.</bullet> </list> <blurb>The solution: Turn off register_globals in development and production environments.</blurb> <list> <bullet>Workarounds could overwrite global variables before PHP 4.4.1 and PHP 5.0.5</bullet> <bullet>Still possible with own importing mechanisms.</bullet> <bullet>Fixed in extract() and import_request_variables().</bullet> </list> <blurb>register_globals and magic_quotes will be removen in PHP 6</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-cookies.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-cookies.xml +++ presentations/slides/php-best-practices/security-cookies.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Cookies and Sessions</title> <blurb>The issue: Cookies can easily be modified by users.</blurb> <list> <bullet>Do not store important information in cookies</bullet> <bullet>Can be faked very easily by automated scripts.</bullet> </list> <blurb>The solution: Use ext/session to store user data.</blurb> <list> <bullet>If available, a session ID will be stored in a cookie automatically.</bullet> <bullet>Data will be stored on the servers filesystem or database.</bullet> </list> <blurb>Hint: Never store passwords as clear text or too simple md5 hash.</blurb> <example result="1"><![CDATA[<?php function getPasswordHash($user, $password) { return md5('mySite' . $user . $password); } echo getPasswordHash('username', 'password'); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-input.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-input.xml +++ presentations/slides/php-best-practices/security-input.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Input validation</title> <blurb>The issue: Validating user input is a nasty task.</blurb> <blurb>The solution: use ext/filter oder ext/ctype</blurb> <example result="1"><![CDATA[<?php var_dump( ctype_alnum( 'foobar_42' ) ); var_dump( ctype_alnum( 'Bad Characters $%&/' ) ); var_dump(filter_data('bob@example.com', FILTER_VALIDATE_EMAIL)); var_dump(filter_data('example.com', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)); ]]></example> <blurb>Hint: For numeric IDs you can simply cast the variable to integer</blurb> <example result="1"><![CDATA[<?php var_dump( (int) '42' ); var_dump( (int) '42; DELETE * FROM users;' ); var_dump( (int) 'Evil string' ); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-intro.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-intro.xml +++ presentations/slides/php-best-practices/security-intro.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - About this section</title> <blurb>What will I learn here?</blurb> <list> <bullet>Common pitfalls and their solution</bullet> <bullet>Paying attention on your user</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-obscurity.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-obscurity.xml +++ presentations/slides/php-best-practices/security-obscurity.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Security by obscurity</title> <blurb>The issue: Knowledge about paths and extensions makes it easier to exploit your system.</blurb> <list> <bullet>Obscurity can be just an additional feature of your security concept</bullet> </list> <blurb>The solution: Hide information</blurb> <list> <bullet>Never have phpinfo() in your webroot. It exposes information about pathes, extensions and configuration.</bullet> <bullet>Turn off display_errors in your production environment. - Use log_errors instead.</bullet> <bullet>Changing default filetypes and disabling expose_php may help, too.</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-permissions.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-permissions.xml +++ presentations/slides/php-best-practices/security-permissions.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Fix the permissions</title> <blurb>The issue: Wrong access permissions makes it easier to take over your webserver</blurb> <blurb>The solution: Fix your access rights</blurb> <list> <bullet>No writeable and excuteable files in your webroot.</bullet> <bullet>No writeable PHP files.</bullet> <bullet>Disallow external read access to files which contains classes, configuration or application code.</bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-sql.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-sql.xml +++ presentations/slides/php-best-practices/security-sql.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - SQL injection</title> <blurb>The issue: Using userdata in queries often causes users manipulating queries.</blurb> <example result="0"><![CDATA[<?php $sql = 'SELECT password FROM user WHERE login = ' . $_GET['login']; ?> Request: http://example.com/tests/simple.php?login=username+OR+1 ]]></example> <blurb>The solution: Use databases extensions escape functions</blurb> <example result="0"><![CDATA[<?php $sql = 'SELECT password FROM user WHERE login = ' . mysql_real_escape_string( $_GET['login'] ); ?>]]></example> <blurb>Hint: Even better use prepared statements</blurb> <example result="0"><![CDATA[<?php $db = new PDO( ... ); $stmt = $db->prepare( 'SELECT password FROM user WHERE login = ?' ); $stmt->execute( array( $_GET['login'] ) ); ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-variables_1.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-variables_1.xml +++ presentations/slides/php-best-practices/security-variables_1.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Variable injection - 1</title> <blurb>The issue: Unintialized variables can lead for unexpected code segments to be executed.</blurb> <example result="0"><![CDATA[<?php if (correct_user($_POST['user'], $_POST['password']) { $login = true; } if ($login) { forward_to_secure_environment(); } ?>]]></example> <blurb>The solution: Initialize your variables</blurb> <list> <bullet>Never trust ANY user input.</bullet> </list> <blurb>Common XSS example: This request will open an JavaScript alert window with text "XSS".</blurb> <example result="0"><![CDATA[ <form action="<?php echo $_SERVER['PHP_SELF']; ?>"> </form> Request: http://example.com/tests/simple.php/%22%3E%3Cscript%3Ealert('xss')%3C/script%3E%3Cfoo ]]></example> <blurb>Variables containing user input: $_POST, $_GET, $_REQUEST, $_COOKIE, $_SERVER, ($_ENV)</blurb> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-variables_2.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-variables_2.xml +++ presentations/slides/php-best-practices/security-variables_2.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Variable injection - 2</title> <blurb>The issue: Variables in include statements can lead to execution of external code</blurb> <list> <bullet>With allow_url_fopen = On (default) external code can be included</bullet> </list> <example result="0"><![CDATA[<?php require_once $_GET['action'] . '.php'; ?>]]></example> <blurb>The solution: Validate included files against a whitelist using arrays or switch statements.</blurb> <example result="0"><![CDATA[<?php $files = array( 'show' => 'show.php', 'list' => 'list.php', ); if (isset($files[$_GET['action']])) { require_once $files[$_GET['action']]; } else { echo 'Not a valid action.'; } ?>]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/security-xss.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/security-xss.xml +++ presentations/slides/php-best-practices/security-xss.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide fontsize="3em"> <title>Security - Output escaping</title> <blurb>The issue: Cross site scripting attacks caused by inproper escaping.</blurb> <list> <bullet>Every user input may contain characters which will be interpreted by the displaying programm.</bullet> </list> <example result="1"><![CDATA[<?php $text = '<b>Hallo</b> Welt.'; echo $text; echo htmlentities( $text ); ?>]]></example> <blurb>The solution: Use escape functions on output</blurb> <list> <bullet>Remember, that database content may be user input to.</bullet> </list> <blurb>Hint: Consider the context of output, or use a template system which automatically takes care of output escaping</blurb> <example result="0"><![CDATA[<?php $config = ezcTemplateConfiguration::getInstance(); $config->context = new ezcTemplateXhtmlContext(); $t = new ezcTemplate(); $t->process( "hello_world.ezt" ); ?>]]></example> <blurb>In eZ Template variables are escaped according to the context of the output</blurb> <example result="0"><![CDATA[ {var $myVar = '<b>Hello world!</b>'} {$myVar} ]]></example> <blurb>To not escape the content of the var, you need to call raw explicitely</blurb> <example result="0"><![CDATA[ {var $myVar = '<b>Hello world!</b>'} {raw $myVar} ]]></example> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/talk.css?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/talk.css +++ presentations/slides/php-best-practices/talk.css <style title="Default" type="text/css"> body { font-size: 10pt; margin-left:290px; margin-right:0em; margin-bottom:0em; background-image: url(presentations/slides/perf/ezp.png); background-attachment: fixed; background-repeat: no-repeat; font-family: verdana, tahoma, arial, helvetica, sans-serif; overflow: -moz-scrollbars-none; } div.sticky { margin: 0; position: fixed; top: 0em; left: 290px; right: auto; bottom: auto; } div.navbar { padding: 4; margin: 0; height: 14em; font-family: verdana, tahoma, arial, helvetica, sans-serif; z-index: 99; } div.navbar_title, div.navbar_title a, div.subtitle { font-size: 32px; color: #698fe5; text-decoration: none; text-align: left; font-weight: bold; margin-top: 20px; } div.subtitle { margin-top: 5px; font-size: 24; font-weight: normal; font-style: italic; } div.navbar_nr a { font-size: 16px; color: #77a; text-decoration: none; position: fixed; right: 10px; bottom: 0px; } div.mainarea { margin-top: 120px; top: 150px; width: 733px; height: 600px; overflow: auto; overflow: -moz-scrollbars-vertical; } ul.pres { list-style: circle; font-size: 20pt; } ul.level2 { list-style: circle; font-size: 20pt; margin-left: 40px; margin-top: -15px; } li.pres_bullet { font-size: 20pt; margin-right: 40px; } li.pres_bullet_nr { font-size: 28pt; margin-right: 40px; list-style-type: decimal; } ul.large div li.pres_bullet { font-size: 40pt; } ul.small div li.pres_bullet { font-size: 20pt; } div.title_blurb { font-size: 80px; text-align: center; font-weight: bold; } div.small_blurb { font-size: 24px; } div.blurb, div.bit_larger_output_text { font-size: 20pt; width: 100%; } div.bit_larger_output_text { margin-top: 10px; } div.x_small_blurb { font-size: 0.5em; } div.large_blurb { font-size: 32pt; } div.large_blurb_center { font-size: 48px; text-align: center; } div.quote { font-size: 48px; text-align: center; margin-left: 40px; margin-right: 40px; } div.quote_attr { font-size: 32px; text-align: right; margin-right: 40px; } div.xx_large_blurb_center { font-size: 80px; text-align: center; } div.q_mark { text-align: center; font-size: 480px; } div.shadow, code { font-size: 18px; width: 640px; } div.example code, div.highlight code, div.bit_larger, div.bit_larger code, div.bit_larger_output { background: #eee; font-size: 23px; width: 100%; } div.example, div.highlight, div.bit_larger, div.bit_larger_output { margin-left: 20px; margin-right: 20px; } div.large code, div.large { font-size: 32px; background: #eee; font-weight: bold; margin-left: 20px; margin-right: 20px; } div.highlight code, div.highlight { background: #fffc00; font-weight: bold; } div.code_small, div.code_medium, div.code_large, div.example { background: #eee; } div.code_small code { font-size: 12px; } div.code_medium code, div.code_medium pre { font-size: 20px; } div.code_large code, div.code_large pre { font-size: 24px; } div.example pre { font-size: 23px; } div.event, div.event-date, div.event-presenter { text-align: center; font-size: 32pt; } div.pres-url-small { text-align: center; font-size: 24pt; } img.spaced { margin-right: 25px; margin-left: 25px; margin-top: 25px; margin-bottom: 25px; } table { font-size: 20pt; } </style> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/thanks.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/thanks.xml +++ presentations/slides/php-best-practices/thanks.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide title="Thank you for listening"> <list> <bullet>I hope you like eZ components!</bullet> <bullet>I hope you learned what you expected!</bullet> </list> <break /> <break /> <list> <bullet>Thank you for inviting me!</bullet> <bullet>It's been a great pleasure to be here!</bullet> </list> <break /> <break /> <blurb> Further questions? </blurb> <list> <bullet>http://ez.no/community/forum/ez_components</bullet> <bullet>Tobias Schlitt <ts@ez.no></bullet> </list> </slide> http://cvs.php.net/viewvc.cgi/presentations/slides/php-best-practices/title.xml?view=markup&rev=1.1 Index: presentations/slides/php-best-practices/title.xml +++ presentations/slides/php-best-practices/title.xml <slide fontsize="3.5em"> <title>Welcome!</title> <break lines="3"/> <blurb class="event">PHP best practices</blurb> <break/> <blurb class="event">The dos and don'ts</blurb> <break/> <blurb class="event-date">FrOSCon, St. Augustin, Germany</blurb> <break/> <blurb class="event-presenter">Kore Nordmann - &lt;kn@ez.no&gt;</blurb> <break/> <blurb class="event-presenter">Tobias Schlitt - &lt;ts@ez.no&gt;</blurb> </slide>