Posts

PHP Best Practise

Always use PHP standard tags i.e.  <?php ?> .  To ensure the future version support, Please use standard tags for PHP. Always follow a consistent naming standards. Always use Indent and white spaces in codes. It helps to read and understand the code. Always turn on the full error reporting for development. It will show you complete list of notices, warnings and errors. When you are sending you code to production, Please make sure that you have turn off the error reporting else problems would be visible to users.  You can turn on the error reporting by php.ini. error reporting can be enabled on runtime by error_reporting() function. Always do the client and server side validation wherever there is scope of user input. You can not trust on your users. Always put comment in your code. It will make it easy to understand to others. You should use caching mechanism for the performance of the site. Ex.- memcache Don’t do the deep nesting. It will make the code complicated. Always avoid ...

Output buffering in php

Output buffering is used by PHP to improve performance and to perform a few tricks. Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script. Advantages of output buffering: Turning on output buffering alone decreases the amount of time it takes to download and render our HTML because it’s not being sent to the browser in pieces as PHP processes the HTML. All the fancy stuff we can do with PHP strings, we can now do with our whole HTML page as one variable. If you’ve ever encountered the message “Warning: Cannot modify header information – headers already sent by (output)” while setting cookies, you’ll be happy to know that output buffering is your answer. Use Facebook to Comment on this Post Output buffering in php

Ternary Operators

This operator takes three arguments – a condition, a result for true, and a result for false. It is a shortcut of doing if statements. Here’s an example:     $result = ($a < 16) ? 'true' : 'false';     if ($a < 16) {         $result = 'true';     } else {         $result = 'false';     } Use Facebook to Comment on this Post Ternary Operators

Cheat Sheets & Quick Reference Cards for Developers | DevCheatSheet.com

Cheat Sheets & Quick Reference Cards for Developers | DevCheatSheet.com

PHP 5.4 beta1 released

The PHP development team announced the first beta release of PHP 5.4. PHP 5.4 includes new language features and removes several legacy (deprecated) behaviors. THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION!

How to check browser cookie enabled with php and javascript

Cookies are typically used by web servers to perform functions such as tracking your visits to websites, enabling you to log in to sites, and storing your shopping cart. Cookies can be used to interaction between Javascript and Server Side Scripts like PHP.Cookies also used to transfer small amount of data between one page to other pages via HTTP headers .If user disables this cookies or user’s browser won’t support the interaction between JS and PHP fails.So we must ensure user must enable these Cookies. Checking with Javascript if (navigator.cookieEnabled == 0) { alert("You need to enable cookies for this site to load properly!"); } Checking with PHP If user disables Javascript we fail to check the Cookie enabled or not.So we check on the server side also.below PHP snippet check the Cookie enabled or not. function check_cookie(){ if (setcookie("test", "test", time() + 360)) { if (isset ($_COOKIE['test'])) { return true; } } return false; }

PHP 5.3.8 Released!

All PHP users should note that the PHP 5.2 series is NOT supported anymore. All users are strongly encouraged to upgrade to PHP 5.3.8.