Suggest a Snippet Login Register
  • LOG IN:

    Not a member? JOIN NOW!
     Username                   Password
    Remember me Recover password
DevSnippets Design Community & Snippets Gallery
  • Subscribe by RSS
>
  • Webdesign
    • Design
    • HTML5
    • lists
    • Menu
    • Navigation
    • Portfolio
    • Showcase
    • Template
    • Tooltip
    • Tutorial
    • webdesign
  • Web development
    • AJAX
    • CodeIgniter
    • CSS
    • CSS3
    • Database
    • Javascript
    • jQuery
    • Mootools
    • MySQL
    • PHP
    • PHP Framework
    • plugins
    • WordPress
    • WordPress Hacks
  • Inspiration
    • Fonts
    • Icons
    • Inspiration
    • Mac
    • Mac apps
    • Photography
    • Wallpapers
  • Snippets
In {Articles} -4th May- {33 Comments}

10 Essential PHP Code Snippets You Might be Looking For

PHP is a scripting language that is perfect for developing dynamic web pages and applications. Being one of the most popular scripting languages on the internet today, makes it pretty easy to get started with. If you are looking for a technique that you forgot about, or a function you didn’t know someone else has created before; then this article might be something useful for you and will save you some time for sure. Today we will highlight 10 Essential PHP functions with step by step tutorials to get you some of the latest techniques used these days.

1. Using PHP to Backup MySQL Databases

If you website stores its data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster (we all have been there). There are different ways to backup your MySQL Database, but today we will only focus on how to use PHP to backup your MySQL database.

Different Ways to backup your MySQL database:

  • 1. Execute a database backup query from PHP file.
  • 2. Run mysqldump using system() function.
  • 3. Use phpMyAdmin to do the backup.

1.1 Execute a database backup query from PHP file

Below is an example of using SELECT INTO OUTFILE query for creating table backup :

<?php
include 'config.php';
include 'opendb.php';

$tableName  = 'mypet';
$backupFile = 'backup/mypet.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);

include 'closedb.php';
?>

To restore the backup you just need to run LOAD DATA INFILE query like this :

<?php
include 'config.php';
include 'opendb.php';

$tableName  = 'mypet';
$backupFile = 'mypet.sql';
$query      = "LOAD DATA INFILE 'backupFile' INTO TABLE $tableName";
$result = mysql_query($query);

include 'closedb.php';
?>

Source

1.2 Backup Your Database into an XML File Using PHP

If you want to have XML backup because it’s easy to read, here’s a PHP snippet that outputs your database as XML.

Further Resources

  • - Bulletproof backups for MySQL

2. User Membership Area With PHP

No matter where you go on the internet, there’s a staple that you find almost everywhere – user registration. Whether you need your users to register for security or just for an added feature, there is no reason not to do it with this simple tutorial. In this tutorial we will learn the basics of user management, ending up with a simple Member Area that you can implement on your own website.
User Membership Area With PHP

Source

3. Asynchronous Comments with PHP, jQuery, and JSON

In the public forum that is the blogosphere, the ability to capture and display visitor comments on your blogs can give you instant feedback and opinions from the people that matter most – those that read your blog. In this article, we’re going to look at how we create a simple but effective means of capturing and displaying visitor comments using a blend of jQuery, PHP and JSON.
Asynchronous Comments with PHP, jQuery, and JSON

Source

4. Using PHP with your Social Media

There are different PHP snippets out there you can use in order to retrieve your bookmarked urls on different social media websites, you can retrieve your tweets and display them in your website or even post your tweets from your website. Below are couple of PHP techniques you can use.

4.1 Update your Twitter status using PHP

We have seen many web application that offers you a way to update your twitter status through their apps. You can add this functionality to your website using the simple script in this post. Don’t forget to add your username, password and message.
Update your Twitter status using PHP

Source

4.2 Get Your Recent Delicious Bookmarks Using PHP

This tutorial uses PHP5 to download and cache your recent bookmarks in RSS format from the Delicious API, then displays them in a HTML unordered list. This tutorial uses SimpleXML.
Source

4.3 Build a PHP Twitter Widget

This tutorial will teach us how to use cURL to get your Twitter status and cache it into a file on your server. This file will then be read with JavaScript and displayed on the web-page.

Build a PHP Twitter Widget
Source

5. Making Forms Work with PHP

5.1 Creating a Register & Login System With PHP, MySQL & jQuery

Learn how to create a simple login / registration system in this step by step tutorial. You will have the ability to easily create a member-only area on your site and provide an easy registration process. It is going to be PHP driven and store all the registrations into a MySQL database.

The script is using sliding jQuery panel, developed by Web-kreation.
Creating a Register & Login System With PHP, MySQL & jQuery
Source

5.2 PHP Online Quote Form

A nice and clean quote form your clients can use to request a free quote for their web projects. The code is using date picker from ElectricPrism which uses Mootools.
PHP Online Quote Form

5.3 AJAX Contact Form with CAPTCHA, Realtime Validator and PHP Backend

An advanced script with many features including CAPTCHA and Real-time Validation. Unlike many AJAX Captchas out there that rely on JavaScript, this one uses PHP to securely generate and register the required code in the background. Moreover, you can specify whether to show letter, numbers or both on the verification image.
AJAX Contact Form with CAPTCHA, Realtime Validator and PHP Backend
Source

6. SQL Injection With PHP

Most web applications interact with a database, and the data stored therein frequently originates from remote sources. Thus, when creating an SQL statement, you often use input in its construction. A typical SQL injection attack exploits this scenario by attempting to send fragments of valid SQL queries as unexpected values of GET and POST data. This is why an SQL injection vulnerability is often the fault of poor filtering and escaping, and this fact cannot be stressed enough.

This article explains SQL injection by looking at a few example attacks and then introducing some simple and effective safeguards. By applying best practices, you can practically eliminate SQL injection from your list of security concerns.

<?php
$sql = "SELECT card_num, card_name, card_expiry
FROM credit_cards
WHERE username = '{$_GET['username']}'";
 ?>

Source & Source

7. Building CMS Using PHP

7.1 Building Simple CMS Using PHP

Jason Lengstorf shows how to build a very simply object-oriented Content Management System with PHP. While not a ready-to-use solution, due to a few security holes, it nonetheless does a good job at teaching a real-world use for PHP. You will find part2 of this tutorial very useful as it cover different security holes the first part didn’t cover. Further reading on security risks and safe PHP code can be found here.

Building CMS Using PHP
Source

7.2 Building Content Editing System Using PHP & jQuery

This tutorial will show you how to use jQuery and PHP to build a content editing system that will allow you or your client to easily edit .html pages visually. The tutorial will use PHP’s file_get_contents() to load the selected HTML file into a text area.
Source

8. Dynamically Create Thumbnails Using PHP

Jeffrey Way shows us how to how to upload files and then have PHP dynamically create a thumbnail. This technique is useful specially When you deal with large images, it’s often necessary to create smaller “thumbnail” versions. Whether you’re building an ecommerce site, or just a simple gallery, these techniques will absolutely prove to be useful.

Dynamically Create Thumbnails  Using PHP
Source

9. Banner Rotator With PHP, jQuery & MySQL

In this tutorial we are going to learn how to make a simple PHP, jQuery & MySQL banner rotator, with which you can create and randomly display banners on your site. Each of the banners features a neat jQuery animation effect, which you can customize to fit your own needs.

Simple Banner Rotator With PHP, jQuery & MySQL
Source

10. YouTube video manager with PHP, MYSQL & jQuery

Youtube is the most popular platform when it comes to upload your videos to the web. It’s therefore likely that some day, as a web developer, you’ll be asked by one of your clients to integrate some YouTube videos on a web page or a social web app.

We’ll learn in this post how with a PHP class, a little MYSQL table made of only 3 fields, and a bit of jQuery code, you can build a very nice Video Manager.

This manager will allow yourself or your client to manage videos easily, without any technical knowledge. We’ll see how you can add a video simply by pasting its YouTube url, how to edit them, and how to delete them thanks to a nice interface.

YouTube video manager with PHP, MYSQL & jQuery
Source

Category: Article | Leave a Comment | 33 Comments

Related Posts

33 Comments, Add Comment or Ping

  1. nick says:
    May 4, 2010 at 4:22 am

    Very nice!!! thanks

  2. djug says:
    May 4, 2010 at 5:25 am

    interesting
    thanks

  3. Alex says:
    May 4, 2010 at 5:52 am

    I am very pleased you liked my article (the Twitter PHP Caching Widget) thanks for including it! :)
    This is also a very good collection of snippets.

  4. johnny rodriguez says:
    May 4, 2010 at 6:49 am

    very kewl

  5. ranyl says:
    May 4, 2010 at 7:44 am

    wow, this is useful to me..

  6. Alex Bilbie says:
    May 4, 2010 at 9:58 am

    Regarding 4.1, this will not work as of June 30th because Twitter are removing basic http auth support. You’ll need to use OAuth instead. See http://countdowntooauth.com/ for more information.

  7. Rachel says:
    May 4, 2010 at 12:31 pm

    Excellent tut…very useful..thanks

  8. Morten Jonassen says:
    May 4, 2010 at 2:08 pm

    Nice! Thanks for this.

  9. Guhan Iyer says:
    May 5, 2010 at 12:09 pm

    Nice set of tools, I especially like the Twitter framework.

  10. Anil Kumar Panigrahi says:
    May 5, 2010 at 9:36 pm

    Very Nice lists of PHP snippets …….

    Thank you very Much.

  11. alireza says:
    May 5, 2010 at 11:26 pm

    see this for your first snippet:
    http://www.noupe.com/php/10-ways-to-automatically-manually-backup-mysql-database.html

    • Noura Yehia says:
      May 5, 2010 at 11:35 pm

      Thanks for bringing out this post to my attention, it was written by me last year on Noupe :)

    • Deluxe Blog Tips says:
      May 6, 2010 at 5:36 am

      Thanks for the link. Although I usually use some backup tools, but this is needed sometimes.

  12. Federica Sibella says:
    May 6, 2010 at 11:34 pm

    Right what I was looking for, thank you so much!

  13. CSSReX says:
    May 10, 2010 at 12:43 am

    Thanks for such a nice scripts. I appreciate that. Very helpful!!

  14. SaiChand says:
    May 18, 2010 at 6:21 am

    Nice Site.
    Great Information.

  15. cvul says:
    May 19, 2010 at 10:58 am

    Good resource. I’ll use one of these codes.

  16. WEBeleven says:
    May 26, 2010 at 2:30 pm

    Thanks for the bundle of useful scripts, thumbs up buddy.

  17. Harsha M V says:
    May 28, 2010 at 11:56 pm

    awesome round up///

  18. Emily says:
    May 31, 2010 at 10:02 am

    Thanks for the bundle of useful scripts, thumbs up buddy.

Trackbacks/Pingbacks

  • designfloat.com
  • 10 Essential PHP Code Snippets You Might be Looking For | TopRoundups
  • 10 Essential PHP Code Snippets You Might be Looking For | pro2go Designs Blog
  • 10 Essential PHP Code Snippets You Might be Looking For | DevSnippets « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit
  • === popurls.com === popular today
  • CSS Brigit | 10 Essential PHP Code Snippets You Might be Looking For
  • links for 2010-05-05 « 個人的な雑記
  • abcphp.com
  • 10 Essential PHP Code Snippets You Might be Looking For « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates
  • ITキヲスク | 2010年5/2~5/8の週間ブックマーク
  • [Linkdump #4] Z kamerą wśród serwerów – elePHPant. | Tomasz Kowalczyk
  • diggita.it
  • AddaZ | Blog | 10 Essential PHP Code Snippets You Might be Looking For

Sponsored Ads

ADVERTISE HERE

Sponsored Ads

DevSnippets Latest Articles

  • Using Illustrations in WebDesign: 30 Creative Examples
    Tags: Illustration, Inspiration, webdesign Jul/20/2010
  • Dark and Mysterious High Quality Desktop Wallpapers
    Tags: Dark, Wallpapers Jun/23/2010
  • 10+ Most Beautiful Island Photography on Earth
    Jun/16/2010
  • 35 High Definition iPad Wallpapers For A Great Experience
    Tags: Inpiration, Wallpapers Jun/09/2010
  • 30 Unique Logo Designs That Actually Say Something
    Tags: Branding, Inspiration, Logo Jun/02/2010
  • Creating 10 Most-Used Javascript Techniques Using Pure CSS Styling
    Tags: CSS, Tutorial May/31/2010
  • 40 Creative Advertisements With Unexpected Ideas
    Tags: Advertising, Inspiration May/27/2010
  • Getting Slim, Spicy, & WordPress-Ready with Top 10 jQuery Plugins
    Tags: jQuery, WordPress May/25/2010
  • Spicing Up Your Tumblr Experience: Beautiful Themes, Icons and Apps
    Tags: Templates, Tumblr May/19/2010
  • 20 NEW & FREE High Quality (X)HTML/CSS Templates
    Tags: CSS, Design, Template, Tutorial May/17/2010
More Articles →

Design Community News

  • Is It Worth Shifting To Photoshop CS5?

    SloDive
    Jul/04/2010
  • Free Wordpress Theme Vector Nature Template

    templates4all
    Jul/04/2010
  • Best jQuery plugins – June 2010

    Spider8411
    Jun/22/2010
  • Freebies: Vintage Mega Pack 10 Samples from Designious.com

    Doink
    Jun/22/2010
  • CSS3 Animations, the Power Back to CSS Part 1: Transitions

    Teylor Feliz
    Jun/22/2010
  • Create a Photo-Realistic Candle with Basic Photoshop Tools

    Frank
    Jun/22/2010
  • Credit cards and payment icon set

    icon sets
    Jun/22/2010
  • 40 Refreshing Nature Inspired Web Designs

    Brukhar
    Jun/22/2010
  • How to Create a Tumblr Theme (Code Structure)

    Dainis Graveris
    Jun/21/2010
  • The Simple Photoshop CS5 Cheat Sheet

    Frank
    Jun/21/2010
More News →

Our Friends

  • Graphic Design School

  • Designm.ag

Top ↑

Add a Snippet / Design News

© 2008-2010 DEVSNIPPETS | Made by Noura Yehia | Submit Snippet | About| Subscribe | Advertise
In partnership with (mt) Media Temple