<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tuyen Vuong on Medium]]></title>
        <description><![CDATA[Stories by Tuyen Vuong on Medium]]></description>
        <link>https://medium.com/@tuyendinhvuong?source=rss-18daea020428------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-GBvW3Z6nFgVXaqW.jpg</url>
            <title>Stories by Tuyen Vuong on Medium</title>
            <link>https://medium.com/@tuyendinhvuong?source=rss-18daea020428------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:03:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuyendinhvuong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ZCE — PHP Object Oriented Programming]]></title>
            <link>https://medium.com/@tuyendinhvuong/zce-php-object-oriented-programming-7356903f078e?source=rss-18daea020428------2</link>
            <guid isPermaLink="false">https://medium.com/p/7356903f078e</guid>
            <category><![CDATA[zend-certified]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[zce]]></category>
            <category><![CDATA[zend]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Tuyen Vuong]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 03:58:43 GMT</pubDate>
            <atom:updated>2019-03-18T03:59:20.412Z</atom:updated>
            <content:encoded><![CDATA[<h3>ZCE — PHP Object Oriented Programing</h3><h3><strong>PROPERTIES &amp; METHODS:</strong></h3><ul><li>Invalid property declaration (dynamic variables (., $, self, CONSTANT, $this))</li><li>Valid property declarations: number, string, null, array</li><li>Visibility keywords: PUBLIC, PRIVATE, PROTECTED</li><li>Property declare <strong>can be assign a constant outside of class </strong>(ex:defined(‘C’,’X’))</li><li>If you declare a property using <em>var</em> instead of one of <em>public</em>, <em>protected</em>, or <em>private</em>, then PHP 5 will treat the property as if it had been declared as <strong><em>public</em></strong></li><li>Methods are functions within a class</li><li>If visibility (methods) is not defined then the default is public</li></ul><h3><strong>STATIC PROPERTIES / METHODS:</strong></h3><ul><li>Keyword: static (::)</li><li>Declaring class properties or methods as static makes them accessible without needing an instantiation of the class</li><li>$this is not available inside the method declared as static</li><li>Static properties cannot be accessed through the object using the arrow operator -&gt;</li><li>(::) can not accessed to class properties</li></ul><h3><strong>INHERITANCE:</strong></h3><ul><li>The visibility (method and properties) must be equal or less restricted than the parent class</li><li>Can not extend more than one class (except interface class)</li><li>Beware the order when extends and instantiated a class</li><li>When the properties of child class not exist or that properties visibility is private in parent class. That’s properties can be declared and assign value</li><li>Can be override constant from parent class</li></ul><h3><strong>ABSTRACT:</strong></h3><ul><li>Classes defined as abstract can not be instantiated</li><li>Not require declared a abstract method in abstract class</li><li>In child class must be declared all method abstract of parent class abstract</li><li>The visibility must be equal or less restricted than the abstract class</li><li>The abstract method can not declared as a private method</li><li>Abstract method can not contain body</li><li>Take care when abstract method is a construct method (may not call)</li><li>Can not inherit abstract method but can override the constants (two class abstract)</li><li>Can be override constant from parent class</li></ul><h3><strong>INTERFACES:</strong></h3><ul><li>The class implements a interface must be declared all interface methods</li><li>The interface class can be extends more than one interface class (<strong>Multiple interface inheritance</strong>). But can not extend from normal class (not interface class)</li><li>Can not inherit previously or override constant from interface class</li><li>The class can be extends one parent class and implements more than one interface class (<strong>class </strong>rain <strong>extends </strong>weather <strong>implements </strong>water)</li><li>The class can inherited methods be used to follow an interface structure</li><li>Interface constants works exactly like <a href="http://php.net/manual/en/language.oop5.constants.php">class constants</a> except they <strong>cannot be overridden by a class/interface that inherits them.</strong></li><li><strong>Can inherit interface method </strong>from others interface class</li><li>The interface may <strong>not include member variables</strong></li><li>The interface may <strong>not contain any body</strong></li><li>The interface <strong>can not instantiated</strong></li><li>All methods declared in an interface must be <strong>public</strong>; this is the nature of an interface.</li></ul><h3><strong>EXCEPTION:</strong></h3><ul><li>Each <a href="http://php.net/manual/en/language.exceptions.php"><em>try</em></a> must have at least one corresponding <a href="http://php.net/manual/en/language.exceptions.php"><em>catch</em></a> or <a href="http://php.net/manual/en/language.exceptions.php"><em>finally</em></a> block.</li><li>The thrown object must be an instance of the <a href="http://php.net/manual/en/class.exception.php">Exception</a> class or a subclass of <a href="http://php.net/manual/en/class.exception.php">Exception</a>. Trying to throw an object that is not will result in a PHP Fatal Error.</li><li>Multiple <a href="http://php.net/manual/en/language.exceptions.php"><em>catch</em></a> blocks can be used to catch different classes of exceptions. Normal execution (when no exception is thrown within the <a href="http://php.net/manual/en/language.exceptions.php"><em>try</em></a> block) will continue after that last <a href="http://php.net/manual/en/language.exceptions.php"><em>catch</em></a> block defined in sequence. Exceptions can be <a href="http://php.net/manual/en/language.exceptions.php"><em>throw</em></a>n (or re-thrown) within a <a href="http://php.net/manual/en/language.exceptions.php"><em>catch</em></a> block.</li><li>Nested Exception…</li></ul><h3><strong>MAGIC METHODS:</strong></h3><ul><li><a href="http://php.net/manual/en/language.oop5.decon.php">__construct()</a>, <a href="http://php.net/manual/en/language.oop5.decon.php">__destruct()</a>, <a href="http://php.net/manual/en/language.oop5.overloading.php">__call()</a>, <a href="http://php.net/manual/en/language.oop5.overloading.php">__callStatic()</a>, <a href="http://php.net/manual/en/language.oop5.overloading.php">__get()</a></li><li><a href="http://php.net/manual/en/language.oop5.overloading.php">__set()</a>, <a href="http://php.net/manual/en/language.oop5.overloading.php">__isset()</a>, <a href="http://php.net/manual/en/language.oop5.overloading.php">__unset()</a>, <a href="http://php.net/manual/en/language.oop5.magic.php">__sleep()</a>, <a href="http://php.net/manual/en/language.oop5.magic.php">__wakeup()</a>, <a href="http://php.net/manual/en/language.oop5.magic.php">__toString()</a>, <a href="http://php.net/manual/en/language.oop5.magic.php">__invoke()</a></li><li><a href="http://php.net/manual/en/language.oop5.magic.php">__set_state()</a>, <a href="http://php.net/manual/en/language.oop5.cloning.php">__clone()</a> and <a href="http://php.net/manual/en/language.oop5.magic.php">__debugInfo()</a> are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them.</li><li><strong>All overloading methods must be defined as public</strong></li></ul><h3><strong>CONSTRUCTORS AND DESTRUCTORS:</strong></h3><ul><li>The same class name construct</li><li>Construct with parameters (If missing argument the warning will be return and we can declared construct with greater than number of argument of construct)</li><li>Precedence <strong>__construct</strong> when a class exist __construct and the same class method</li><li>Can not defined private construct (magic method must declared as public).</li><li>The destructor will be called even if script execution is stopped using <a href="http://php.net/manual/en/function.exit.php">exit()</a>. Calling <a href="http://php.net/manual/en/function.exit.php">exit()</a> in a destructor will prevent the remaining shutdown routines from executing. OR <strong>unset</strong>($obj)</li></ul><h3><strong>STANDARD PHP LIBRARY (SPL):</strong></h3><ul><li>The Standard PHP Library SPL is a <strong>collection of interfaces and classes</strong> that are meant to solve common problems</li><li>No external libraries are needed to build this extension</li><li>SPL provides a set of standard data structure, a set of iterators to traverse over object, a set of interfaces, a set of standard Exceptions, a number of classes to work with files</li><li><strong>ArrayObject</strong> implements <a href="http://php.net/manual/en/class.iteratoraggregate.php"><strong>IteratorAggregate</strong></a> , <a href="http://php.net/manual/en/class.arrayaccess.php">ArrayAccess</a> , <a href="http://php.net/manual/en/class.serializable.php">Serializable</a> , <a href="http://php.net/manual/en/class.countable.php">Countable</a></li><li><strong>ArrayIterator</strong> implements <a href="http://php.net/manual/en/class.arrayaccess.php">ArrayAccess</a> , <a href="http://php.net/manual/en/class.seekableiterator.php"><strong>SeekableIterator</strong></a> , <a href="http://php.net/manual/en/class.countable.php">Countable</a> , <a href="http://php.net/manual/en/class.serializable.php">Serializable</a></li><li><strong>Generator</strong> implements <a href="http://php.net/manual/en/class.iterator.php">Iterator</a></li></ul><h3><strong>COMPARING OBJECTS:</strong></h3><ul><li>When using the comparison operator (==), object variables are compared in a simple manner, namely: Two object instances are equal if they have the same attributes and values and are <strong>instances of the same class</strong></li><li>When using the identity operator (===), object variables are identical if and only if they refer to the <strong>same instance of the same class</strong></li><li><strong>The comparison operation stops and returns at the first unequal property found.</strong></li></ul><h3><strong>OBJECT CLONING &amp; FINAL KEYWORD:</strong></h3><ul><li>Will call magic method __clone</li><li>Clone current status of object (not original)</li><li>Use clone to copy new object (very different when we use assignment = because the object will auto create a reference to other object)</li><li>If want to keep the properties of clone object we can use <strong>reference ($this-&gt;pro = &amp;$this-&gt;pro)</strong> or <strong>static</strong> properties.</li><li>When an object is cloned, all of the object’s properties. Any properties that are references to other variables, will remain references</li><li>PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.</li><li>If try to override the classes or methods have final keyword at prefix the fatal error will be return</li><li><strong>Note</strong>: Properties cannot be declared final, only <strong>classes</strong> and <strong>methods</strong> may be declared as final.</li></ul><h3><strong>TRAITS:</strong></h3><ul><li><strong>As of PHP 5.4.0, PHP implements a method of code reuse called Traits</strong></li><li><strong>Precedence: Class Method &gt; Trait Method &gt; Inherited Method</strong></li><li><strong>Multiple Traits: </strong>(use Hello, World;)</li><li><strong>Conflict Resolution: (</strong><em>insteadof</em> <em>)</em></li><li><em>If two traits insert a method with the same name, a fatal error is produced</em></li><li><em>Can not declare a property the same property with trait</em></li><li><strong>Changing Method Visibility: </strong><em>Use HelloWorld { sayHello as protected AliasName; }</em></li><li><strong>Traits Composed from Traits: </strong>Just as classes can make use of traits, so can other traits (<em>Trait HelloWorld { use Hello, World; }</em>)</li><li><strong>Abstract Trait Members: </strong><em>Trait Hello { abstract public function getWorld(); }</em></li><li><strong>Static Trait Members: </strong>Traits can define both static members and static methods. But not affect to change or increase static variables (just like normal variables)</li><li><strong>Properties: </strong>Traits can also define properties.</li></ul><h3><strong>SCOPE RESOLUTION OPERATOR:</strong></h3><ul><li><strong>$this</strong> refer to current object</li><li><strong>self</strong>:: refer to current class</li><li><strong>parent</strong>:: refer to parent class</li><li><strong>static</strong>:: Late static bindings tries to solve that limitation by introducing a keyword that references the class that was initially called at runtime.</li><li>CASE IN-SENSITIVE</li></ul><h3><strong>VISIBILITY:</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7356903f078e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP Security Quick Notes]]></title>
            <link>https://medium.com/@tuyendinhvuong/php-security-quick-notes-713aaf943603?source=rss-18daea020428------2</link>
            <guid isPermaLink="false">https://medium.com/p/713aaf943603</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[zend]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[zend-certified]]></category>
            <category><![CDATA[zce]]></category>
            <dc:creator><![CDATA[Tuyen Vuong]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 03:18:15 GMT</pubDate>
            <atom:updated>2019-03-18T03:53:16.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>ZCE — PHP Security Quick Notes</h3><h3><strong>Configurations:</strong></h3><ul><li><strong>error_reporting</strong> = E_ALL &amp; ~E_DEPRECATED; (when coding, enable also E_STRICT)</li><li>to disable error reporting entirely on the running code (<strong>display_errors = off; log_errors = on; error_log=$path;</strong>)</li><li><strong>allow_url_include</strong> = off; <strong>allow_url_fopen</strong> = off (on by default) — network resources will still be accessible through fsockopen or CURL functions.;</li><li><strong>expose_php= off</strong>; in php.ini file, the amount of information available is reduced</li><li>disable_functions , disable_classes</li><li><strong>HTTP authentication</strong>: pre-defined variables <strong>PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE</strong></li><li><strong>cgi.force_redirect</strong>: prevent running PHP as CGI redirect</li><li><strong>doc_root</strong>: make sure no script executed outside this directory</li><li><strong>user_dir</strong>: if NULL when access url ~user/dir/script.php will be open under doc_root, if set “userdir” then the url will refer to home/user/userdir/dir/script.php</li><li><strong>open_basedir</strong> — Restricts PHP’s file access to one or more specified directories, can be tightened at runtime</li><li>may use .htaccess to parse every file (including .html,etc.) by php so as to hide PHP from possible attackers</li></ul><h3><strong>Session:</strong></h3><p><strong>Preventing Session Fixation:</strong></p><ul><li>Set <a href="http://us2.php.net/manual/en/session.configuration.php">session.use_trans_sid = 0</a> in your php.ini file</li><li>Set <a href="http://us2.php.net/manual/en/session.configuration.php">session.use_only_cookies = 1</a> in your php.ini file</li><li>Regenerate the session ID anytime the session’s status is changes</li></ul><p><strong>Preventing Session Hijacking:</strong></p><ul><li><a href="http://php.net/manual/en/session.configuration.php"><em>session.cookie_httponly</em></a><em> = 1 </em>and <a href="http://php.net/manual/en/session.configuration.php"><em>session.cookie_secure</em></a><em> = 1</em></li><li>use enough random input for generating the session ID (see <a href="http://php.net/manual/en/session.configuration.php"><em>session.entropy_file</em></a>, <a href="http://php.net/manual/en/session.configuration.php"><em>session.entropy_length</em></a>, and <a href="http://php.net/manual/en/session.configuration.php"><em>session.hash_function</em></a>)</li><li>Include the <a href="http://php.net/manual/en/reserved.variables.server.php">user agent </a>in the session</li><li>Change the name of the session from the default PHPSESSID</li><li>Use a strong session hash identifier: <a href="http://us2.php.net/manual/en/session.configuration.php">session.hash_function</a> in php.ini</li><li>Include a token in the session and on the browsers side that you increment and compare often. Basically, for each request do $_SESSION[‘counter’]++ on the server side</li></ul><h3><strong>Cross Site Scripting (XSS)</strong></h3><p><strong>Omitting untrusted input for the moment [a tag]:</strong></p><ul><li>There is a URL Context, i.e. the value of the href attribute</li><li>There is a HTML Attribute Context, i.e. it parents the URL Context.</li><li>There is a HTML Body Context. i.e. the text between the &lt;a&gt; tags.</li></ul><p><strong>Preventing Cross-Site Scripting In PHP:</strong></p><ul><li>Never pass data from untrusted origins into output without either escaping or sanitising it.</li><li>Each Context requires a different method of escaping because each Context has different special characters and different escaping needs. You cannot just throw <strong>htmlspecialchars</strong>() and <strong>htmlentities</strong>() at everything and pray that your web application is safe.</li></ul><h3><strong>Cross Site Request Forgeries (CSRF)</strong></h3><p><strong>Introductions:</strong></p><ul><li>CSRF is a separate vulnerability from XSS, with a different solution. XSS protections won’t stop CSRF attacks, although XSS are important to solve and should be prioritized</li><li>Attacks HTML objects, Attacks scripting code, Attacks XML HTTP Request, CSRF with AJAX Attack</li></ul><p><strong>Conditions:</strong></p><ul><li>Page that the attack does not check the source of messages, or HTTP referrer header</li><li>Web browser allows users faking the header</li><li>The attacker is in able to specify the victim to open a malicious web links.</li></ul><p><strong>Preventing CSRF:</strong></p><ul><li>Only accept POST</li><li>Referrer checking</li><li>Requiring multi-step transactions: CSRF attack can perform each step in order</li><li>CAPTCHA Systems</li><li>One-time tokens</li><li>Same origin policy</li><li>Reconfirm password</li><li>XSS Output Filtering (HTML Encoding)</li></ul><h3><strong>SQL INJECTION</strong></h3><ul><li><strong>Set </strong>privileges for each application</li><li>Prepared statements</li><li>Stored procedures</li><li>Principle of least privilege when connecting to DB</li><li><strong>Validation and filtering</strong></li><li>Correct PHP and database configuration</li><li>Good database design</li><li><strong>Escaping Output</strong></li></ul><h3><strong>REMOTE CODE INJECTION</strong></h3><p><strong>Conditions:</strong></p><ul><li>REMOTE CODE INJECTIONS RUN THE ATTACKER’S CODE ON A SERVER</li><li>THE eval(), exec(), AND system()FUNCTIONS ARE VULNERABLE TO REMOTE CODE INJECTIONS</li><li>OTHER VULNERABLE FUNCTIONS: preg_replace WITH THE /e PATTERN MODIFIER; create_function(), include, fopen…</li></ul><p><strong>Prevent:</strong></p><ul><li>CHECK DATA AGAINST A WHITELIST</li><li>REMOVE PATHS USING basename()</li><li>SET <strong>allow_url_fopen = Off , allow_url_include=</strong>Off <strong>in php.ini</strong></li><li>disable_functions = ‘…’</li><li><strong>escapeshellargs</strong>() TO ESCAPE ARGUMENTS</li><li><strong>escapeshellcmd</strong>() TO ESCAPE COMMANDS</li></ul><h3><strong>EMAIL INJECTION</strong></h3><ul><li>Validation input and Escape Output</li><li>Use regular expressions to filter user data</li><li>Use external components and libraries that provide protection against this problem like ZEND mail, PEAR mail and swift mailer.</li><li>ModSecurity can put a stop to email injection on the server level. With ModSecurity, it is possible to scan the POST or GET body for BCC, CC, or To and reject any request that contains those letters.</li><li>DO NOT PROVIDE OPEN RELAYS</li><li>OPEN THE SMTP PORT ONLY IF ESSENTIAL</li><li>USE A “TARPITS” TECHNIQUE TO SLOW REQUESTS AS A MEANS OF DISSUADING ATTACKS</li></ul><h3><strong>INPUT FILTERING</strong></h3><ul><li><strong>Never Blacklist; Only Whitelist</strong></li><li>Blacklisting involves checking if the input contains <strong>unacceptable</strong> data while whitelisting checks if the input contains <strong>acceptable</strong> data</li><li>Filter what you can’t Validate</li><li>Be Wary Of Context</li><li>Evade PHP Type Conversion</li><li>PHP Functions:</li><li>ctype_*</li><li>filter_*</li></ul><p><strong>INPUT FILTERING</strong></p><ul><li>Data Type Check</li><li>Allowed Characters Check</li><li>Format Check</li><li>Limit Check (length)</li><li>Presence Check</li><li>Verification Check</li><li>Logic Check</li><li>Resource Existence Check</li></ul><p><strong>ESCAPE OUTPUT</strong></p><ul><li>Escape HTML, XML, JSON feed, Excel, AJAX</li><li><em>Escape output when you’re outputting, not before</em></li><li><em>XML: SimpleXML, DOMDocument</em></li><li><em>HTML: htmlspecialchars, htmlentities, strip_tags</em></li><li><em>JAVASCRIPT: htmlspecialchars, json_encode, quotemeta</em></li><li><em>Characters: &lt; &gt; ‘ “ &amp;</em></li></ul><h3><strong>PASSWORD HASHING API</strong></h3><ul><li><strong>Hash Collision: </strong>occurs when two different data inputs generate the same resulting hash (hash functions)</li><li><strong>Rainbow Tables: </strong>10 million password hashes and run auto login (prevented by adding a <strong>salt and unique salt</strong>)</li><li>password_hash() — used to hash the password.</li><li>password_verify() — used to verify a password against its hash.</li><li>password_needs_rehash() — used when a password needs to be rehashed.</li><li>password_get_info() — returns the name of the hashing algorithm and various options used while hashing.</li></ul><h3><strong>FILE UPLOADS</strong></h3><ul><li>Store the file outside of your document root (should not have any “execute” permission.)</li><li>Check the file size</li><li>Keep tight control of permissions</li><li>Limit the number of uploaded files</li><li>Protecting the upload folder with .htaccess</li><li>Checking the image header [getimagesize]</li><li>Mime Type Validation and Extension File. Using White-List for Files’ Extensions</li><li>Block Dangerous Extensions (.htaccess)</li><li>Generate a random file name and add the previously generated extension</li></ul><h3><strong>DATA STORAGE, SSL…</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=713aaf943603" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>