background preloader

PHP

Facebook Twitter

43 Ways to Optimize your PHP Code. Build PDF files dynamically with PHP. Sometimes you need control over exactly how pages are rendered for printing. At times like those, HTML is not the best choice. PDF files give you complete control over how pages are rendered and how text, graphics and images are rendered on the page. Sadly, APIs for building PDF files are not standard parts of the PHP toolkit.

Now is the time to bring in a little help. When you search the web for PDF support for PHP, the first thing you are likely to find is the commercial PDFLib library and its open source version, PDFLib-Lite. Another choice is the Free PDF library (FPDF), which is native PHP. Listing 1. The root element for the XML is an events tag. Listing 2. getresults.php This script implements a getResults function that reads the XML file into a DOMDocument.

To test that this script works, you will build an HTML export page that uses the getResults function to read the file, then outputs the data as a series of HTML tables. Listing 3. Building the PDF Listing 4. Listing 5. PHP & MySQL – Preventing MySQL Injection. Posted at Good PHP Tutorials by Ross Tanner In this tutorial I am going to explain what MySQL injection is and how important it is to prevent this attack on your database(s). It is vital that all security measures are in place before you make your website live because the effects can be devastating especially if you store sensitive data. Lets start with the basics and learn what MySQL injection is. How to Process Credit Cards with PayPal Payments Pro Using PHP. Namespaces With PHP. PHP namespaces was introduced in version 5.3. Namespaces is a way of group classes together into virtual directories, the main reason we would want to do this is to help avoid collision of class names in your application.

In PHP you can not define two classes with the same name, if you do this PHP will display a fatal error in your application. Using namespaces means that you can define two classes with the same name as long as they are in different namespaces. For example if you had two classes both named Table and both classes perform different tasks, one will be used to read a database table and the other will be used to display a HTML table. If these are not in namespaces then PHP will throw a class is already defined error, the old way of fixing this problem would be to prefix the class name with something unique. The database table class would now be called Database_Class and the HTML class will now be called Html_Class. Defining Namespaces.

Formatted Strings With PHP. When you are using PHP to output a string on the page most of the time you will use the syntax echo, which will take the following string and display that string in HTML.

Formatted Strings With PHP

You can even concaternate multiple strings or variables together to be outputted by the echo syntax. Here is an example of using echo to output multiple options in a select box. As you can see from the echo syntax that you can create a HTML element by using PHP. This code uses a concatenated string to insert the variables into the value attribute and a title inside the option tag. Test Driven Development With PHP. 21 Really Useful & Handy PHP Code Snippets. Posted at WebDeveloper+ Contents Human Readable Random String.

21 Really Useful & Handy PHP Code Snippets

Creating web services using PHP. Posted at Web Developing using Open Source Technologies by Mohammed Diab What is web service?

Creating web services using PHP

First of all I want to explain or define what is web service. You can think of web services as DLL files over the web. You write the code, then compile it and every one can use it whatever language they are using. But in the web you don’t compile anything. Create a Photo Admin Site Using PHP and jQuery. Posted at Nettuts+ by Jeffrey Way I’m pleased to present you with part one of a two part series on creating a photo site using PHP, jQuery and AJAX.

Create a Photo Admin Site Using PHP and jQuery

Originally, I intended to fit the entire tutorial into one screencast, but that quickly became a pipe dream as I realized that there was simply too much to cover. Nevertheless, even if you only watch this first video, you should learn a great deal. We’ll be retrieving images from a database, creating a simple login form with authentication and will then allow for our database to be asynchronously updated. Sounds good? Our goal For this lesson, our goal is to create a photo admin section where an administrator can retrieve photos from a database and update the title of his photos simply by clicking on the appropriate text. PHP: The Right Way. Hot php Scripts.

List of Videos for PHP. How to Create a PHP/MySQL Powered Forum from Scratch. Making a site admin page in PHP. PHP & MySQL For Dummies Cheat Sheet. Cheat Sheet When writing PHP programs to create your Web database application and communicate with a MySQL database, you have many things to remember.

PHP & MySQL For Dummies Cheat Sheet

You must spell code correctly and use perfect syntax. This Cheat Sheet provides a reference for quickly looking up the correct syntax for the code you use most frequently. PHP MySQL Web Development Security Tips. We are closing down our forums, it’s time to move on, but we are keeping some important threads, here is one… I read about many of these points in books and tutorials but I was rather lazy to think about many of them initially learned some of these lessons the hard way.

PHP MySQL Web Development Security Tips

Fortunately I didn’t lose any major data over security issues with PHP MySQL, but my suggestion to everyone who is new to PHP is to read these tips and apply them *before* you end up with a big mess. If you are expecting an integer call intval() (or use cast) or if you don’t expect a username to have a dash (-) in it, check it with strstr() and prompt the user that this username is not valid. Here is an example: $post_id = intval ( $_GET [ 'post_id' ] ) ; mysql_query ( "SELECT * FROM post WHERE id = $post_id " ) ; Now $post_id will be an integer for sure JavaScript validation is only good to reduce the server load. Use mysql_real_escape_string() to escape the user input. Next and Previous Posts With Thumbnails. Media rich content is engaging content, right?

Next and Previous Posts With Thumbnails

And giving readers an opportunity to browse through posts linearly is one good way to keep them at your site reading longer, right? So why just give them a title? This quick tip will give you the programming you need to include the post thumbnail and the date of the next and previous posts. Building Your First Simple CMS.

The Magic of PHP + MySQL It’s safe to say that nearly every website that’s up-to-date these days is using some form of content management system (CMS).

Building Your First Simple CMS

While there are a ton of great free options that provide us with a CMS to power a website (WordPress, Drupal, etc.), it doesn’t hurt to peek under the hood and get a feel for how these systems work. To get our feet wet as back-end developers, we’ll be creating a simple PHP class that will: Create a databaseConnect to a databaseDisplay a form with two fieldsSave the form data in the databaseDisplay the saved data from the database Download Files. Backup Your MySQL Database Using PHP. One of the most important tasks any developer needs to do often is back up their MySQL database.

Backup Your MySQL Database Using PHP

In many cases, the database is what drives most of the site. While most web hosts do a daily backup of a customer's database, relying on them to make backups and provide them at no cost is risky to say the least. That's why I've created a database backup function that I can call whenever I want -- including nightly CRONs. The PHP & MySQL Code Of course, you'll need to provide database credentials to the function, as well as an array of tables you'd like to backup. Never take chances when your website is on the line. FPDF Library. How to Connect to a Database with PDO. We've covered PHP's PDO API a couple of times here on Nettuts+, but, generally, those articles focused more on the theory, and less on the application.

How to Connect to a Database with PDO

This article will fix that! To put it plainly, if you're still using PHP's old mysql API to connect to your databases, read on! What? It's possible that, at this point, the only thought in your mind is, "What the heck is PDO? " Creating a Flat-File Blog Engine Using Slim. In this article, we will learn how to create a flat file blog engine in PHP using the Slim framework. If you don't understand the jargon, don't worry. We're simply going to create a spartan blogging application, which utilizes text files instead of a database to store data. If you're a beginner, fret not! We will start with the basics of using Slim. Let's get started after the jump! Introduction. Automatic Face Detection in Photos with PHP. Practical PHP Programming.