PhpRiot
PhpRiot Authors
PhpRiot Latest Articles by Quentin Zervaas
63 articles by Quentin Zervaas

Accessing the Twitter API Screencast

In this screencast I'll show you how to access the Twitter API using PHP. We'll use cURL to list a user's timeline and then to output tweets from a user's list.

Anti-Spam Techniques In PHP, Part 1

This short series of articles provides a few simple techniques for protecting yourself and your web site from spammers. It does this from two perspectives: 1. Protecting people (including yourself) who post to your web site from being spammed 2. Protecting your web site from being spammed (for example, blog spam)

Anti-Spam Techniques In PHP, Part 2

This short series of articles provides a few simple techniques for protecting yourself and your web site from spammers. It does this from two perspectives: 1. Protecting people (including yourself) who post to your web site from being spammed 2. Protecting your web site from being spammed (for example, blog spam) This is the second article in the series, and covers the issue of protecting your web site from spammers.

Application Logic Versus Template Logic

This article takes a look at separating application logic from template logic. We will use the Smarty Template Engine as the basis for the article and its examples.

Cloning Google Suggest With Ajaxac

This article covers how to implement a system such as Google Suggest using JavaScript, CSS and PHP. To aid us in this process we will be using AjaxAC, an open-source framework written in PHP used to develop AJAX style applications. We will be implementing a clone of this application, from start to finish. This begins with setting up our frontend HTML file and CSS styles, creating our AjaxAC GoogleSuggestCloneJax application, and then linking it all together.

Combining PHP, JSON and jQuery Screencast

In this screencast I'll show you how simple it is to make PHP communicate with a JSON data source using jQuery's Ajax functionality.

Creating A Fulltext Search Engine In PHP 5 With The Zend Framework's Zend Search Lucene

This article covers the implementation of a fulltext search engine using PHP 5 and the Zend Framework. We will be using the Zend_Search_Lucene component to create and search our fulltext index.

Creating Custom Block Tags in Smarty

Smarty is a very powerful template engine for PHP that allows developers to extend its capabilities using custom plug-ins. There are several different types of plug-ins, each of which serves a different purpose. In this article we will look at how the block plug-in type works.

Creating Multi-Step Forms And Wizards In PHP

There will be many situations when creating web forms, that either you cannot accept all data on one page, either because certain responses result in a different set of subsequent questions, or because you form is so long that you need to split it up into multiple pages. The case could even be that you have a 1 page form, but you want to show confirmation of the form data prior to processing the data (e.g. showing a user their order before processing their credit card). This tutorial covers how to implement such forms using PHP. This will include covering the various issues that need to be taken into consideration, as well as a class to help build such forms. Finally, there will be real-world example of implementing a multi-page form using the class.

Creating Search Engine Friendly URLs In PHP Updated

One of the major reasons for using a server-side language such as PHP is for the ability to generate dynamic content. Often this will lead to single scripts that produce their content based on the input parameters (that is, the variables in the URL). This article covers various techniques and methods for representing these parameters in the URL in a clean and "friendly" manner, as well as then how to read the parameters.

Creating Sortable Lists With PHP And Ajax

You might have been in a situation before where you had a list of items in your database that needed to be output in a specific order. These items could be anything: perhaps a listing of your favourite movies or your favourite books. For whatever reason, you want them ordered in a custom way that can't be determined automatically (such as alphabetical). This article covers the implementation of a system that lets you easily define the order of such a list.

Creating XHTML Compliant Code

This article contains a few simple pointers to make sure all your HTML code is XHTML compliant. This will be an evolving document as there will periodically be new ideas and methods of doing things. It's amazing that despite how simple and fundamental all of these things are, very few people coding HTML get them right.

CSS Tips

Here is a list of CSS-related tips. They are basic things you can do within your CSS file and/or HTML files to make your pages faster to download; faster to render; work in more browser; be accessible; be maintainable.

Debugging Your Web Application

This article covers the implementation of a debugging system in your web site or web application. The system is designed to allow debugging of different aspects of your system at any particular time (e.g. SQL queries, filesystem operations, etc..) and writing the debug messages to a log file.

Detecting Ajax Requests With PHP

In this PhpRiot Snippet I will show you how you can check if a HTTP request is an Ajax request.

Downloading a Remote File With cURL and PHP

In this PhpRiot Snippet I will show you how to download a file from another web site and save it to disk.

Eight Weeks of Prototype: Week 1, Beginning with Prototype

Prototype is a JavaScript framework used to help with development of cross-browser code that is easy to maintain and extend. In this first article of "Eight Weeks of Prototype" I will teach you the fundamentals of Prototype, which you will hopefully find useful for all JavaScript code you write.

Eight Weeks of Prototype: Week 2, How Prototype Extends Elements

When you select elements from the Document Object Model (DOM) using the functions Prototype provides, each returned element is extended with extra functionality. In this, the second article in "Eight Weeks of Prototype," I will show you exactly how Prototype extends these elements.

Eight Weeks of Prototype: Week 3, Prototype Data Types

In this, the third article in the "Eight Weeks of Prototype" series, I will teach you about the different data types that can be used in Prototype (on top of the existing JavaScript data types). We will firstly look at the basic string and number types, then look at enumerable types such as arrays and hashes.

Eight Weeks of Prototype: Week 4, Event Handling in Prototype

One of the most useful and important aspects of JavaScript developments is that of event handling. Prototype simplifies this process by providing a number of helpful methods for doing so. In this, the fourth article of "Eight of Weeks of Prototype", we will look at how Prototype helps with handling events.

Eight Weeks of Prototype: Week 5, Ajax with Prototype

In addition to all of the other useful classes Prototype gives to developers, it also provides a number of classes and methods for development of Ajax-enabled web applications. That is, it allows developers to easily perform HTTP sub-requests using XmlHttpRequest and to handle the response accordingly. In this article I will show you how Prototype makes Ajax development for developers by covering the functionality it provides. Additionally, I will show you how to easily transfer data between your JavaScript code and web server using JSON data.

Eight Weeks of Prototype: Week 6, Writing JavaScript Classes with Prototype

While JavaScript is by design an object-oriented language, it hasn't always been the easiest language to create nicely structured code that is easily maintainable. Prototype helps with this by providing a number of useful features for creating classes, such as the ability to extend classes and to easily group all functions together by using function binding. In this article I will show you how to create classes using JavaScript and Prototype.

Eight Weeks of Prototype: Week 7, Other Prototype Functionality

So far in Eight Weeks of Prototype I have covered the most important aspects of developing robust JavaScript using Prototype; however I haven't covered every available feature. In this article I will briefly discuss other aspects of development with Prototype, that while aren't necessarily core knowledge are still useful.

Eight Weeks of Prototype: Week 8, A Complete Prototype Example

So far in this series, "Eight Weeks of Prototype," I have shown you some of the extensive features the Prototype JavaScript framework provides. In this, the final article of the series, I will bring many of these features together into a simple example.

Fetching Data With Zend_Db

In this PhpRiot Snippet I will show you a couple of different ways to fetch data when using the Zend Framework's Zend_Db component.

Generating Static Images of Google Maps

One useful feature of Google Maps is the ability to generate a static image of any longitude and latitude that you desire, as opposed to using the normal JavaScript-based interactive map. In this article I will show you how to request such static images. We will then combine this technique with the geocoder we created in the article Geocoding with PHP and the Google Maps API.

Geocoding with PHP and the Google Maps API

Geocoding is the process of finding the longitude and latitude of a given address or location. The Google Maps service gives developers and web site owners free access to their geocoder, both using the Google Maps JavaScript API, as well as using the web service. In this article I will show you how to access the geocoder web service using PHP so that it can be used in your own applications.

Implementing A Breadcrumbs System On Your Site

This article briefly covers implementing a breadcrumbs / trail system. An example of this in action is on this web site (see above where it says "You are here".

Implementing An N-Level Nested Tree In PHP And PostgreSQL Appendix

Since creating the second part of the Nested Tree series, I've done further work on the nested tree class. This appendix article is not officially part of the "3 part series", but it is an addon article which may be continually updated with new ideas and snippets to include in the Nested Tree class. The reason these have been kept separate is because they are not core to the concept of implementing nested trees in your web site.

Implementing An N-Level Nested Tree In PHP And PostgreSQL, Part 1

This series of articles is about implementing a nested tree using PHP and PostgreSQL. The theory and code in these articles also applies to MySQL, not just PostgreSQL. An N-Level nested tree is a way to represent hierarchical data, such as a list of directories and files in your operating system, or the listings in a directory such as the Open Directory Project. There can be any number of levels and any number of elements within each level. The goal is to be able lookup data in the tree as quickly as possible with minimal strain on resources. We will implementing this using the nested tree model by Joe Celko.

Implementing An N-Level Nested Tree In PHP And PostgreSQL, Part 2

This series of articles is about implementing a nested tree using PHP and PostgreSQL. This article - part 2 - covers the implementation of managing nested trees in PHP. The data we learned how to store in SQL in part 1 must be extracted somehow. In this article, we will create a class used to extract data from the tree and to rebuild the tree. Each portion of the class will be developed separately, then all combined into a single class.

Implementing a WebDAV filesystem with PHP and SabreDAV

In this article I will show you how to create a WebDAV filesystem using PHP and the open-source library SabreDAV. Doing so allows you to map your web site as a local drive on your computer, meaning you can add, edit, move and delete files and folders on your web site just as you would with other files on your computer.

Managing Your Data With DatabaseObject

DatabaseObject is a class I wrote three or four years ago, as a way of easily manipulating database data. It is not a replacement for a database abstraction class. In fact, it works very nicely with a database abstraction class, however, the version we have provided uses the native PHP PostgreSQL and MySQL database calls.

Migrating From MySQL To PostgreSQL In PHP

This article is aimed primarily at MySQL users, showing them how to start with the PostgreSQL database management system. The article covers just a small number of areas, directly related to use in PHP - it barely even touches on most of PostgreSQL's other features.

Monitoring File Uploads using Ajax and PHP

Because of the limitations of HTTP, it is difficult to monitor the status of files as they are uploaded via HTML forms. While other programming languages have built-in methods to monitor file uploads, PHP does not. This article shows how to implement such a solution in PHP. We will use Ajax to retrieve information about a file as it is being uploaded and display the progress back to the user.

Other Uses For Smarty

Many people think of the Smarty Template Engine as a system for separating presentation from application logic. This is indeed true, but many people also only consider Smarty for outputting their web site HTML/XHTML. This brief article goes over other situations where Smarty may be useful in your PHP application.

PHP A to ZCE: Arrays

Arrays in PHP are the most useful and versatile data structure available. In this article I cover all of the important points you need to know about to leverage the power of arrays in PHP.

PHP A to ZCE: Bitwise Operations

Bitwise operations allow evaluation and manipulation of specific bits within an integer. In this article I will show each of the bitwise operations that are available and how to practically use them within PHP.

PHP A to ZCE: Cookies

Cookies are used to store data on the computer of somebody who visits your web site. In this article I will show you how cookies work and how you can read and write cookies.

PHP A to ZCE: Databases and SQL

Databases are an extremely useful tool in web development as they allow you to store data about users, customers, e-commerce products and orders, or anything else. In this article I will cover the basics of using databases in PHP, including how to manage data using SQL.

PHP A to ZCE: Error Handling

One of the features of PHP is its comprehensive error-handling functionality. You can control many aspects of how errors are triggered and handled. In this article I will cover the key aspects of errors and error handling in PHP.

PHP A to ZCE: Functions

One of the key features of nearly all programming languages is the ability to create reusable code that can be used on-demand. In PHP this is achieved with the creation of user-defined functions. In this article I will show you how to define and use functions in PHP.

Protecting Your PHP Source Code With ionCube Encoder

One of the issues PHP developers face is that PHP is an interpreted language, meaning PHP source code is readable by anybody who downloads your applications. In this article I will show you how to protect your intellectual property by encoding your PHP source code.

Reducing a Map Path Using Douglas-Peucker Algorithm

When drawing a path on a map (for instance, the directions from point A to point B) it is important to consider the limitations of the device you're drawing the path on. In this article, I will show you how to reduce the number of points in a path so the path can be displayed with minimal loss of quality on devices such as iPhone or Android-powered devices that may struggle with an extremely large set of points.

Reminding Users to Submit Forms

This article discusses a simple technique to remind users to submit a form on your web site before navigating to another page. This is especially useful for long forms where the submit button may be hidden at the bottom of the page, or when editing content in a content management system. The technique described in this article uses JavaScript and works in modern browsers such as Internet Explorer, Firefox and Safari.

Searching Google With The Google API

This article covers performing search queries on Google using their API. This means you can transparently run a Google search in the background, and then present the results to your users however you want to. The Google API is a SOAP web service. SOAP (Simple Object Access Protocol) is an XML schema used for calling a remote procedures (usually) over the web. In this case, the remote procedure is Google search. In this article, we are going to create a single PHP script called google.php, to simply demonstrate how to query Google. Hopefully using this information, you will be able to come up with more advanced ways of using the API.

Shortening URLs for goo.gl with Google's URL Shortener API

In 2010 Google released its own URL shortener, which allows you to shorten URLs to use the goo.gl domain. In this article I will show you how to easily create your own short URLs using their new URL shortener API.

Singleton Classes in PHP

In this PhpRiot Snippet I will show you how to create and use singleton classes.

Speeding Up Your PHP Web Site

Google have recently announced that the speed of a web site is now used as a factor in determining its search rank. This is great news for the skillful PHP developer, since it allows you to gain an advantage over those not as dedicated to their art. In this article I will show you some of the steps I've taken to improve the performance of PhpRiot.com. These are all techniques you can easily adapt to your own web sites and web applications.

Storing Images in MySQL Revisited

This article shows you how you can store images in MySQL using the Blob column type. I will show you to create a file upload form, then store the uploaded file in the database. The concepts covered in this article can apply to all files in general, not just images. This is an updated version of a similar article that already appears on PhpRiot.

Translating Text Using the Google Translate API and PHP, JSON and cURL

Google Translate is a service from Google that you can use to translate text or HTML from one language to another. One of the great features of this service is that they now offer an API to let you programmatically translate text. In this article I will show you how to interact with the Google Translate API.

Using Callback Functions in PHP

A commonly used technique when programming is to use callbacks. A callback is a piece of code that is passed to a function that is later executed by that function. In this article I will show you how to define and call callbacks in PHP, as well as a practical example of how callbacks can be useful.

Using Return Codes in PHP

In this PhpRiot Snippet I will show you to execute a command on your server and use its return code.

Verifying Apple App Store Receipts For In App Purchases With PHP and cURL

In this PhpRiot snippet I will show you how to verify a purchase receipt that was submitted by the iOS application with the Apple receipt verification service. We will achieve this using PHP and cURL and the App Store receipt verification service.

Zend Framework 101: Zend_Cache

In this article I will introduce you to the Zend_Cache component of the Zend Framework. This component is used for improving the performance of your web application by saving generated data for later reuse.

Zend Framework 101: Zend_Gdata_YouTube

The Zend Framework contains a number of APIs for accessing Google services, including YouTube. In this article I will show you how to retrieve a feed of videos from YouTube using Zend_Gdata.

Zend Framework 101: Zend_Loader

In this article I will introduce you to Zend_Loader, a Zend Framework class used to automatically load other classes. Typically you would use include_once or require_once when you want to load a class but using Zend_Loader you don't have to.

Zend Framework 101: Zend_Log

This article shows you how to use Zend_Log, the logging component of the Zend Framework. It allows you to record messages from your application however you please. In this article I will show you how to record messages to a log file. Additionally, if you use the Firebug and FirePHP plug-ins for Firefox, Zend_Log can be extremely useful for application development and debugging. I will also show you how to achieve this.

Zend Framework 101: Zend_Oauth

OAuth is a standard that allows to share protected data with other sites. In this article I will show you how to use the Zend_Oauth component of the Zend Framework. To demonstrate how to use Zend_Oauth we will create a script that posts a status update to Twitter for the authenticated user.

Zend Framework 101: Zend_Registry

In this article in the Zend Framework 101 series I will introduce you to the Zend_Registry class. This class used is to allow you manage variables and objects in the global application namespace. This is used as an alternative to using global variables in PHP. I will show you how to use the Zend_Registry class and also provide a practical example of where it would be useful to use the registry.

Zend Framework 101: Zend_Service_Amazon_S3

In this article I will introduce you to the Zend_Service_Amazon_S3 component of the Zend Framework. This component makes use of Amazon Web Services (AWS) to manage files on Amazon's Simple Storage Service (S3).

Zend Framework 101: Zend_Session

In this article I will introduce you to the Zend_Session component of the Zend Framework. This component is built upon PHP's native session-handling functionality, making it easier to manage session data, as well as providing more advanced features.

Zend Framework 101: Zend_Soap

In this article I will introduce you to the Zend_Soap component of the Zend Framework. This component allows you to easily create and consume SOAP web services. We will create a simple web service with several methods using Zend_Soap_Server, and consume the service with Zend_Soap_Client.