Do you have a custom Content Management System (CMS) and wanted to include a handy way for your viewers to link to many of the popular social bookmarking sites like Ma.gnolia.com, Technorati or Digg? Many of the popular blogging applications (drupal, WordPress, etc) have plugins for this, but I wrote my own function, since I don't normally use those applications. I thought I'd pass it along to anyone that is interested.
First you will need to download a zip archive of png images. You can download that here.
Next, we'll need to create a database table to store our bookmark information. This will store linkage format, image and bookmark site. We will treat our URLs as templates, with placeholders for URL and your blog title.
Bookmark to:
Search Engine Optimization (SEO) : Tune up your META
Today I wanted to discuss the importance of META tags for Search Engine Optimization. To generate traffic to your site you must ensure that your site or blog is well indexed and the proper keywords have good weight in your site. I recently found the "Meta Tag Analyzer" tool located here.
The first step is to input your URL, select the visiting UserAgent (defaults to GoogleBot), but you can supply your own Agent if needed.
After the script analyzes your site, you'll be presented with a report. This report has some great information including warnings and errors that you should correct. One common error that occurs is creating values that are not robot friendly due to length. This tool will let you know if you have too many keywords or if your title is too long.
Bookmark to:
Connecting to eBay's API to return real-time auction information for your web site.
eBay offers multiple ways of gathering and displaying auction information for your web site. For example they offer the following methods in their affiliate program:
Editor Kit - javascript based content that pulls auction data (very simple to use)
RSS Feed Generator - eBay offers RSS feeds, where you would be able to pull the feed and parse the XML for your page.
Flexible Destination Tool - Simple re-write of a link to attach your affiliate information. My example will use this as well.
API Developer Kit - Communicating with eBay's web service to return XML results.
The first step is to join eBay's affiliate program (You must have a valid eBay account first). http://affiliates.ebay.com/
By joining (eBay uses CommissionJunction), you'll be able to monetize your site by presenting auctions and with every click you could cash in on commissions.
The next step is to join the eBay developers program. You will need to do this to begin working with their API tools/services. http://developer.ebay.com/join/
After joining the developer program, create development keys. These keys are required for communicating with their web service and they are also used to generate the user authentication token.
http://developer.ebay.com/DevZone/account/keys.asp
Once keys are made it's time to create your authentication token.
http://developer.ebay.com/tokentool/
Once you've joined all the programs, have your keys and authentication token, it's time to write some code!
First, we'll assign some local variables with the keys and token we created earlier. eBay also provides a 'sandbox' server to test with. Please do your testing here first, and after all things are working, change it to the production server.
Bookmark to:
How-to to dump line items from a text file into a MySQL database using PHP
Here is a quick how-to to dump line items from a text file into a database. You can also use INFILE for mysql if you're using CSV. This example is if you're needing to pull line items and then manipulate the data for whatever reason prior to inserting into a MySQL database.
This uses two important functions. fopen() and fgets(). fopen() will open the file. The 'r' flag is for 'reading'. Other possible parameters would include 'a' for 'appending' and 'w' for writing. After opening a file handle to the file, use fget() to grab the contents into a buffer. These will be individual lines in the file. My example explodes on the colon, but you could parse any data at this point and assign values to local variable.
Bookmark to:
Client side validation on Multi-Select form control when working with PHP
Today I wanted to talk about how to do client side validation on a multiselect form control in PHP environment. PHP handles the multiselect form control a little differently in the $_POST array. For this to be sent to the server side script and contain multiple elements, the control name must include [].
<select name="foo[]" multiple="yes" size="5">
....
</select>
This will make $_POST["foo"] and array, where you can then loop through the array object and handle the selected options. I recently ran into a problem with validation. I normally like to do both server side and client side validation on my form objects. I do client side validation just for the sake of client convenience. This will save a server call to find out that something is required or invalid. This is 'fake' security, since you cannot trust the client for proper validation, since they can turn off JavaScript, etc. So I always back up my validation with server side handling to ensure that data is clean.
Bookmark to:
php | architect (The magazine for PHP professionals)
I wanted to talk about PHP Architect. This is an absolutely great magazine and a must-have for any PHP programmers out there. This is a print magazine, but you can subscribe to a PDF version as well, or get the magazine in both formats.
The articles are in-depth and are geared toward serious PHP programming. No "Hello World" examples in here. Topics range from XML to Security to PHP frameworks. I find it incredibly useful for getting new ideas, or to find new directions to research to stay with the current development of PHP.
One thing that I've always appreciated is that fact that PHP Architect takes a default approach to security. Nothing grinds me more than examples without any security considerations. They expect you to add security later, but don't realize that they might be causing more harm than good. PHP Architect seems to always have security and good practice in all of their examples.
Bookmark to:
Creating a simple RSS XML feed using PHP
RSS is a great way to syndicate content of your site. RSS readers are becoming more and more popular. Also community web site such as technorati and ping-o-matic make it great to share and post your content/blogs. RSS is the future, so it's best to get on it.
This how-to will explain how to create a RSS/XML feed using PHP and cron to do a daily XML dump of content stored in a database.
The first step is to create a directory above the web root. Let's name it /cron. In this directory we'll create a PHP-CLI script or command-line script. This script will be executed by cron.daily, so every night at 3AM this script will run. This will not need any interaction with a web browser, but you'll need the ability to create an executable PHP script on the web server and have access to your crontab.
Next let's create the file rss.php in our newly created /cron directory. I'll break it down and explain it as we go through the script. After creating the file we need to assign the interpreter to process the script.
#!/usr/bin/php
<?
Bookmark to:
