background preloader

Build seven good object-oriented habits in PHP

Build seven good object-oriented habits in PHP
Make your PHP applications better with object orientation Nathan GoodPublished on October 28, 2008 In the early days of PHP programming, PHP code was limited to being procedural in nature. Procedural code is characterized by the use of procedures for the building blocks of the application. Procedures offer a certain level of reuse by allowing procedures to be called by other procedures. However, without object-oriented language constructs, a programmer can still introduce OO characteristics into PHP code. While purely procedural designs without much modularity run just fine, the advantages of OO design show up in the maintenance. Modularity— one of the key characteristics of good OO design — helps with this maintenance. While there are more than seven habits to building OO software overall, the seven habits here are what you need to make your code fit basic OO design criteria. The seven good PHP OO habits are: Be modest Bad habit: Expose public fields Listing 1. Listing 2. Listing 3.

Practical PHP Programming Qcodo Development Framework - Home PHP encryption for the common man Consider how today's world differs from the world of just 20 years ago. Long ago, in the 1980s, encryption was spy stuff -- something you read about in a techno-thriller by Tom Clancy. If somebody wanted to keep a bit of information private, he encrypted the data with a password, a pass phrase, or another basic method. Fast-forward to today and encryption is everywhere. Passwords are stored encrypted in databases. Encrypted tunnels through cyberspace are possible via SSL, SSH, and other technologies -- not to mention virtual private networks. As a PHP developer, you should be aware that strong security practices aren't just for exotic applications -- they're for the project you're working on now. There's not enough time or room to discuss every aspect of encryption here, but you'll learn the essentials that will cover most situations you'll find yourself in. Cryptography primer Cryptography is the art of "secret writing," as the word's Greek roots attest. Listing 1. Listing 2. Summary

45+ Best free PHP classes and libraries for Faster Development PHP: Hypertext Preprocessor (the name is a recursive acronym) is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. And, as a feature-rich language, it is possible to accomplish many tasks by default from handling e-mails to images, PDFs to database connections, etc. You may be interested in the following modern trends related articles as well. What is PHP? PHP stands for PHP: Hypertext PreprocessorPHP is a server-side scripting language, like ASPPHP scripts are executed on the serverPHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)PHP is an open source softwarePHP is free to download and use However, there are Best free PHP classes and libraries which helps you get more like: good looking chartsform validationparsing feedsbetter image or database handlingand more. Content BackPress PHP User Class phpSEO PHP Typography Tag Cloud Handling Documents PHPExcel PHPPowerpoint

PHP include() and require() How to Upload files with PHP » Martin Gardner.co.uk In this Tutorial I’m going to outline the process of how you can use a simple PHP script to upload files directly to your server, re-naming them and storing them in a chosen location, all from a very simple form which you can style and place anywhere on your webpages… things to keep in mind for this script to function properly you will require the following: Web hostingPHP 5 or above installedWrite access to a directory on your web serversome PHP knowledge ( to allow for your own customization)basic CSS & Colour values to style your form Before we get to any code you’re going to need a HTML form, in order to pass information to the script, like the name of the file, size, file extension etc… but for this script we will only have to deal with the name of the file. below is an html form with some basic CSS styles applied purely for aesthetic reasons of my own. The PHP The CSS The First part of the code initialises the first two variables and assigns them with no value.

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.

'MySQLi' for Beginners Introduction Nearly every site that you visit nowadays has some sort of database storage in place, many sites opt to use MySQL databases when using PHP. However, many people haven't yet taken the step to interacting with databases properly in PHP. Here we guide you through what you should be doing - using PHP's MySQLi class - with a hat-tip to the one way that you definitely shouldn't be doing it. The Wrong Way If you're using a function called mysql_connect() or mysql_query() you really need to take note and change what you're doing. Any of the functions that are prefixed with mysql_ are now being discouraged by PHP themselves as visible on this doc page, instead you should look to use one of the following: Each has its advantages, PDO for example will work with various different database systems, where as MySQLi will only work with MySQL databases. PHP MySQLi Connecting Obviously, the database name is optional and can be omitted. Querying Output query results Number of returned rows <? <?

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.

Automatic Face Detection in Photos with PHP I have always wondered how to detect faces automatically with php script. I have seen in many photo sharing and social network sites automatically detect a face and tag a name after being uploaded. In this article, i will explain how possible this task can be achieved with simplicity with OpenCV and PHP Facedetect extension. Both are free to download and opensource. Goal To auto detect faces in a photo and draw pink box around the faces with a php script running a linux centos server. Requirements - Linux server running Centos with SSH access - PHP/Apache - GD Library - OpenCV [Download] - PHP Facedetect extension [Download] PHP facedetect extension is very simple. Installation We install opencv and then we compile the php facedetect extension with php. How to Install OpenCV If you are running centos then one single line will install opencv. yum install opencv OpenCV may also need the following depencies to work properly and you will need to install them as well. How to test run OpenCV . run . then

30 game scripts you can write in PHP, Part 1: Creating 10 fundamental scripts Getting started As both a game master/storyteller and a developer, I frequently find myself writing little utilities and scripts to help me when running, planning, and playing games. Sometimes I need a quick idea. Other times, I just need a whole pile of names for Non-Player Characters (NPCs). Occasionally, I need to geek out on numbers, work out some odds, or integrate some word puzzles into a game. Many of these tasks become more manageable with a little bit of script work ahead of time. This article will explore 10 fundamental scripts that can be used in various types of games. We will blaze through these scripts pretty quickly. Back to top A basic die roller Many games and game systems need dice. In many cases, that would be more or less fine. Listing 1. function roll () { return mt_rand(1,6); } echo roll(); Then we can pass the type of die we want to roll as a parameter to the function. Listing 2. Random name generator Listing 3. Listing 4. Listing 5. Scenario generator Listing 6. Summary

How to Create an Infinite Scrolling Web Gallery When working my way through a web gallery, I find it annoying when I must change pages; so in today's tutorial, we will learn how to create an auto-generating, one-page, infinite scrolling gallery with PHP and AJAX. Let's get started! Step 1: Project Outline We'll begin with a normal gallery page that has a container for our images, and we'll monitor the scroll position by calling a JavaScript function at a quick interval. Step 2: HTML Markup We'll work with a very basic setup: a header and the container for our images. Step 3: CSS The CSS is also quite basic. Step 4 Then, for the container and images, I used a bit of CSS3 to add round corners and shadows. Step 5: PHP Script This is going to be very short. We define a variable for the directory we want to get the image names from, test if it exists, and if we can open it, read all the file names from it. Step 6 Now we have to build our response text. As a result, we get the remainder of the division between these two elements. Step 7 Step 9

PHP: Hypertext Preprocessor How to create chained select with PHP and jQuery? In this article we’ll talk about the chaining of select also called select cascade. It is a procedure that we often find on the web and it consists in giving the user the possibility to find a specific data through a few passages: practically choosing a category in the first select, the second one will be populated with the results related with the category selected. We imagine, for example, a first select where it is possible to choose between motorcycles and cars; once we selected the car category , the second select will be populated with the brands of the cars available. You can examine what we will create in this page of example. As you can see, the example is very minimalist. Create the structure of the database So we are going to create a table called categories with the fields id_catname And another table called type with the following fields id_typeid_catname This way we can determine the correct relation between the tables. Preparation of the main page So here the whole class:

Related: