Monday, July 27, 2009

PHP Tutorial on Classes, Inheritance, Polymorphism, Magic Methods & Exceptions

This page will consist of various articles and tutorials on PHP, e.g.: PHP5 Tutorial, PHP Examples, PHP Class, etc. Read on to find out.

Image watermark with PHP

To prevent quality images being stolen, we can use PHP to watermark web-images in popular formats like GIF/PNG/JPEG. We print a transparent gif-image on a jpeg-photo in this tutorial. For best results use gif than png, because some png formats require extra functions to print a transparent image. We can convert this script to a batch-watermarker easily to watermark photo albums/galleries with multiple pictures by putting code in a loop or create a function.

Steps:

1.Load both images
2.Get size of both images
3.Copy watermark to main image
4.Print image to screen

How to Implement Text to Speech in PHP

Festival, application allows us to convert Text to Speech(WAV) format. In this article we will learn on how we can convert text to speech from PHP applications.

Facebook like Autosuggestion with jQuery, Ajax and PHP.

This article shows how to implement Autosuggestion search with jquery...

MySql Prepared Statement in PHP

Prepared Statements are always better than normal statements as it prevent SQL Injection etc. This article will discuss on how we can make Prepared Statement Call to MySql Database Call using MySqli Extension of PHP.

Getting Started with Drizzle and PHP

When It Rains, It Drizzles
Unless you've been completely out of touch with the open source world, you'll have heard of Drizzle, a new database server that's derived from MySQL. The Drizzle project aims to build a "smaller, lighter, faster" version of MySQL that offers similar stability and ease of use, but strips out certain features from the core system in order to improve performance and scalability.

Now, while Drizzle is still relatively new, it is quickly gaining attention among open source developers who are interested in experimenting with it, contributing to it, and using it in their projects. And that's where this article comes in. Over the next few pages, I'll guide you through the process of getting started with Drizzle, showing you how to compile and install it, set up a Drizzle database, and connect to it using PHP. Let's get started!

Friday, July 24, 2009

Regex Coach

The Regex Coach is a graphical application for Windows which can be used to experiment with (Perl-compatible) regular expressions interactively. It has the following features:

It shows whether a regular expression matches a particular target string.
It can also show which parts of the target string correspond to captured register groups or to arbitrary parts of the regular expression.
It can "walk" through the target string one match at a time.
It can simulate Perl's split and s/// (substitution) operators.
It tries to describe the regular expression in plain English.
It can show a graphical representation of the regular expression's parse tree.
It can single-step through the matching process as performed by the regex engine.
Everything happens in "real time", i.e. as soon as you make a change somewhere in the application all other parts are instantly updated.

Thursday, July 16, 2009

PHP performance tips

1. Profile your code to pinpoint bottlenecks
2. Upgrade your version of PHP
3. Use caching
4. Use output buffering
5. Don't copy variables for no reason
6. Avoid doing SQL queries within a loop
7. Use single-quotes for long strings
8. Use switch/case instead of if/else

Wednesday, July 01, 2009

10 Useful PHP Tips

1. Use an SQL Injection Cheat Sheet
2. Know the Difference Between Comparison Operators
3. Shortcut the else
4. Drop Those Brackets
5. Favor str_replace() Over ereg_replace() and preg_replace()
6. Use Ternary Operators
7. Memcached
8. Use a Framework
9. Use the Suppression Operator Correctly
10. Use isset() Instead of strlen()

PHP File Upload Security Ideas

When you allow users to upload files to your website, you are putting yourself at a security risk. While nobody is ever completely safe, here are some precautions you can incorporate to make your site safer.

1.Check the referrer: Check to make sure that the information being sent to your script is from your website and not an outside source. While this information can be faked, it's still a good idea to check.

2.Restrict file types: You can check the mime-type and file extension and only allow certain types to be uploaded.

3.Rename files: You can rename the files that are uploaded. In doing so, check for double-barreld extensions like yourfile.php.gif and eliminate extensions you don't allow, or remove the file completely.

4.Change permissions: Change the permissions on the upload folder so that files within it are not executable. Your FTP program probably allows you to chmod right from it.

5.Login and Moderate: Making your users login might deter some deviant behavior. You can also take the time to moderate all file uploads before allowing them to become live on the web.

How can I execute PHP code on my existing myfile.html page?

The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html:

AddType application/x-httpd-php .html

Or for .htm

AddType application/x-httpd-php .htm

If you only plan on including the PHP on one page, it is better to setup this way:
AddType application/x-httpd-php .html
This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages.