background preloader

PHP snippets

PHP snippets

Ten PHP Best Practices Tips that will get you a job | PHP vs .Net Posted by blake on Jun 4, 2008 in Code, Performance, PHP | 167 comments The last couple of weeks have been quite the experience for me. I was part of a big layoff at my former company, which was interesting. I've never been in that position before, and it's hard not to take it personally. Find the errors in the following code: So, give it a shot. If you got the missing comma in the parameter list, the "new Array()" error, the colon instead of a semi-colon, the '=' instead of '=>' in the foreach statement, and the erroneous use of '+' on the echo line, then congratulations, you found all the errors! That's not how I answered the question though. After pointing out the actual errors, I made a point of adding comments about those things I just mentioned. So, read on for my Ten PHP Best Practices Tips that will get you a job: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. That being said, I hate all you space-indenters. … sorry, pet peeve. Anyway, I hope these tips are helpful.

10 Advanced PHP Tips Revisited - Smashing Magazine Advertisement Here, on the Smashing Editorial team, we always try to meet the expectations of our readers. We do our best to avoid misunderstandings, and we try to spread knowedge and present only the best design practices and development techniques. However, sometimes we do make mistakes. In November 2008 we published the article 10 Advanced PHP Tips To Improve Your Programming21. 10 Useful PHP Tips Revisited by Chris Shiflett and Sean Coates This article is a rebuttal to 10 Advanced PHP Tips To Improve Your Programming21 — henceforth referred to as the previous article — published last November here on Smashing Magazine. Listed below are 10 excellent techniques that PHP developers should learn and use every time they program. Unfortunately, the intrigue devolves into disappointment. 1. This particular tip is just a link to a useful resource with no discussion on how to use it. The root cause of SQL injection is a failure to escape output. Escaping preserves data in a new context. <? 2. <?

pChart | a PHP Charting library TCPDF - PHP Class for PDF It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website. <div style="font-family:helvetica,arial;font-size:small;padding:0 4px 0 4px;background-color:#FFFFCC;color:#003399;border:1px;border-style:solid;border-width:1px;border-color:orange;"><form action=" method="post"><div><input type="hidden" name="cmd" value="_donations" /><input type="hidden" name="business" value="paypal@tecnick.com" /><input type="hidden" name="lc" value="US" /><input type="hidden" name="item_name" value="Tecnick.com" /><input type="hidden" name="no_note" value="0" /><input type="hidden" name="currency_code" value="GBP" /><input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest" /> It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements.

Object passing (with and without serialization) in php - This article will show you how to handle in a proper way a very common situation: a user logs in your site and you want to keep trace of his details while he browses around your site using just one Imagine you have done a site (an e-commerce one e.g.) and you have a nice login page. Your users will insert their username and password and if the data they insert is correct, they are redirected e.g. to the catalog page where they can buy your products. Many of us do this almost everyday buying stuff from many different sites. // we have surely remembered to put // session_start(); // at the beginning of our .php page // process user input here if (user has inserted correct vals) { // retrieve firstname, lastname, id, username from database and store them // retrieving code here $rs=mysql_fetch_array($qry); session_register('username'); session_register('firstname'); session_register('lastname'); session_register('id'); $username=$rs['username']; $firstname=$rs['firstname']; $lastname=$rs['lastname']; $id=$rs['id']; // now in every page where we put session_start() we're able to access this 4 vars } ? Nice huh? Very simple class. include('class.php'); session_start(); ? ?

7 Secure, Lightweight, and Easy to Use PHP Frameworks Choosing a good PHP frameworks can help you develop complex Rich Internet Applications quickly, with a best practices oriented approach, and saving a lot of time reusing code snippets that are already available. There are a lot of interesting PHP frameworks you can choose for your next web project. Which framework you choose is really a personal decision. There is no one “best” framework on the market at the moment. Today we will focus on 7 secure, lightweight and easy to use PHP Frameworks. Why Use a PHP Framework? There are plenty of reasons to use a PHP Framework to build your websites. 1. Below we’ve covered some of the best frameworks available today. 1. CodeIgniter is a powerful, high-performance, open-source PHP framework that helps you author PHP applications rapidly. CodeIgniter has an exciting online manual, a couple of helpful video tutorials and an active user forum. Useful Resources for getting started with CodeIgniter 2. Useful Resources for getting started with Kohana 3. 4.

10 tools for Modern PHP Development | DaveDevelopment Featured Posts Coding DCI in PHP I recently taken a closer look at DCI, this post describes my investigation as to how viable implementing DCI in PHP might be php dci bdd behat featured oop Silex Controllers as Services Using a custom controller resolver, we can create controllers as services much like how it's done with the full stack Symfony framework php featured silex dependency injection How I'm doing TDD with PHP I've been watching the Destroy All Software back catalog over the last couple of months and it's really inspired me to up my TDD game. php tdd bdd rambling behat phpunit featured Handling Symfony2 Events Asynchronously How many of your event listeners need to act synchronously? php symfony2 event driven architecture featured open source message queues silex Phpmig - Simple migrations for php Phpmig is a simple migrations system that was written to be easily adopted regardless of the framework or libraries you are using. php migrations pear featured open source Browse more blog posts

Simple Layouts with PHP This tutorial is for those starting out in PHP and want to learn a great way to create layouts. This will help reduce redundancy and keep you from writing too much code. Download the Source Anyone that has been developing HTML based sites for some time has undoubtedly ran in to the issue of keeping the design consistent across multiple pages. Most websites follow a similar layout to the picture. This is great unless you have sites that require multiple pages. Technique #1 A lot of sites follow this kind of layout scheme The first technique is the entry level solution that works across nearly all situations. <! Take out everything up to the point and put that in a new file called head.php. <? Now just put whatever HTML/PHP content you want in between those two include statements and check it out in a browser. It may be easier to think of it as a puzzle, you are piecing together a complete HTML page with includes. Technique #2 Alright we have that under our belt let’s look at another solution. <!

Top 20+ MySQL Best Practices Database operations often tend to be the main bottleneck for most web applications today. It's not only the DBA's (database administrators) that have to worry about these performance issues. We as programmers need to do our part by structuring tables properly, writing optimized queries and better code. In this article, I'll list some MySQL optimization techniques for programmers. Before we start, be aware that you can find a ton of useful MySQL scripts and utilities on Envato Market. Most MySQL servers have query caching enabled. The main problem is, it is so easy and hidden from the programmer, most of us tend to ignore it. The reason query cache does not work in the first line is the usage of the CURDATE() function. Using the EXPLAIN keyword can give you insight on what MySQL is doing to execute your query. The results of an EXPLAIN query will show you which indexes are being utilized, how the table is being scanned and sorted etc... After adding the index to the group_id field:

8 Best Open Source Shopping Carts Hey Everyone, On Sunday I was contacted by a client and they said the needed a shopping cart up by Monday. Since they needed this cart up so fast I went to the easiest solution I knew, Open Source Shopping Carts. I browsed through tons of shopping carts and put together a list of only the best carts. The list is below. is robust, professional grade e-Commerce shopping cart that you can download, install, and use for free. is a powerful, free PHP/MySQL shopping cart system that is easy to install and customize. Tags: e-commerce, mySql, Open Source, perl, PHP, shopping carts

CakePHP: the rapid development php framework. Pages PHP: What You Need To Know To Play With The Web - Smashing Magaz Advertisement In this article, I’ll introduce you to the fundamentals of PHP. We’ll focus on using PHP to access Web services and on turning static HTML pages into dynamic ones by retrieving data from the Web and by showing different content depending on what the user has entered in a form or requested in the URL. You won’t come out a professional PHP developer, but you’ll be well on your way to building a small page that uses Web services. What Is PHP? PHP is a server-side language that has become a massive success for three reasons: It is a very easy and forgiving language. Installing PHP Locally, And Your First Code To run PHP locally on your computer, you’ll need a local server with PHP enabled. In this file, type (or copy and paste) the following: <? If you open this file in a browser by accessing your XAMPP or MAMP installation (via or you should see the following: But you won’t see that. <? PHP blocks start with <? <? <ul><? <? <?

extremely useful PHP classes PHP PSD Reader A few weeks ago, I wrote an article about this PHP which allow you to display any Adobe PSD file on screen. Very usefull to create preview of PSDs designed for clients, for example.Download Browser detect One of the most common (and boring) problem for front-end developers is definitely cross-browser compatibility. Akismet Remember those days without spam? ADOdb The large majority of websites and web apps are using databases to store all kinds of data. HTML Purifier As it name tells, HTML Purifier is a PHP class created to help you writing a better code. Google charts API Charts are very useful and highly asked by clients, but they can be a lot of work. pChart pChart is another chart class, and it is as good as Google charts API. PHP Excel Excel documents are highly popular in the corporate world. Country from IP Some websites are able to detect your location and automatically display information related with your language. Cache Manager WPGet

9 Tips For Working with MySQL Databases MySQL is one of the most popular relational database management systems (RDBMS) around, with over 6 million installations. It’s a fantastic choice for any new developer, because of its open source nature, wide support and abundance of tutorials available on the subject. Here are some great tips and tools (beside phpMyAdmin) to improve your MySQL coding, and to help you save time. Installing SQL If you’re a newbie to the server side coding arena, don’t worry. Installing SQL is very, very simple. Mac only PHP, SQL & Apache Installer Windows, Linux & Mac installer A windows only LAMP installer MySQL Server 5.1 If you just want MySQL server, and like using command line then this might suit you. For info on how to install and work with the MySQL server, check this NetTuts tutorial: Everything You Need to Get Started With MySQL. SQL Tips 1- Optimize your code SELECT * FROM clients; What’s up with that? That single line of code is highly inefficient. SELECT name, phone, address FROM clients; 7- Caching

Related: