Boolean

PHP5 date() Function

php-logo

Whilst migrating a clients website to a new server today I came across an unexpected error:

Strict Standards: date() function.date: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. (etc)

Well, if you are on shared hosting you most likely do not have access to the php.ini file in order to set the timezone.
Instead head along to your .htaccess file and add the folllowing line:
php_value date.timezone [your_zone] where [your_zone] is found from the link here

PHP5 date() Function Read More »

PHP 5 Mailer Class

phpmailer

I spent about a day creating a basic mailer class until I decided that there had to be a much better implementation created by a third party. Whilst it was interesting to have to iron out the bugs in the examples I found on the internet ultimately I wanted a solid, secure platform for both myself and my customers. There are a lot of code snippets on the internet that just are not up to the job…

So, the one to use is PHPMailer from Codeworx Technologies. Find their link here and access the script from their SourceForge page

For reference my functional example is located here
Let me know if you require a more detailed explanation of how it works.

Update: this page has been getting a few views, so it is obviously something that people are interested in. As of this edit (20/05/2010) the version is 5.0.0.0

Features include:

  • Supports emails digitally signed with S/MIME encryption!
  • Supports emails with multiple TOs, CCs, BCCs and REPLY-TOs
  • Works on any platform.
  • Supports Text & HTML emails.
  • Embedded image support.
  • Multipart/alternative emails for mail clients that do not read HTML email.
  • Flexible debugging.
  • Custom mail headers.
  • Redundant SMTP servers.
  • Support for 8bit, base64, binary, and quoted-printable encoding.
  • Word wrap.
  • Multiple fs, string, and binary attachments (those from database, string, etc).
  • SMTP authentication.
  • Tested on multiple SMTP servers: Sendmail, qmail, Postfix, Gmail, Imail, Exchange, etc.Good documentation, many examples included in download.
  • It’s swift, small, and simple.

PHP 5 Mailer Class Read More »

Free Microsoft Press E-Book:Microsoft® Visual C#® 2008 Express Edition: Build a Program Now!

ms_ebook

To celebrate its 25th Anniversary, Microsoft Press is offering a free e-book:

Microsoft® Visual C#® 2008 Express Edition: Build a Program Now!

By Patrice Pelland
ISBN: 9780735625426

Get this Free e-book now from here, Sign up to download the entire e-book (PDF, 7.8 MB)

Some people have experienced difficulties because it downloads a file called ‘pdf_loader.pl’. So proceed with the download, and once it is complete rename the file with an extension of .pdf and it will work!

Free Microsoft Press E-Book:Microsoft® Visual C#® 2008 Express Edition: Build a Program Now! Read More »

Scriptaculous list sorting with AJAX callbacks

sorting

An outline of what we are trying to achieve:

  1. Populate list values from a database and render them onscreen
  2. Use JavaScript to setup the sortable items 
  3. Add a JavaScript callback to the drag/drop pointing to a serialising function to send an AJAX request to the server
  4. Create a server-side script that loops through the list updating the database with the new order

You will need the prototype library: http://prototypejs.org/
And of course the Scriptaculous library: http://script.aculo.us/downloads

To enable this methodology there are several files:

  • test.php – contains the list and necessary JavaScript
  • request.php – necessary to processes our AJAX request
  • db.inc – a database class that is included in both index.php and request.php to make the connection to the DB and has methods to get the current list and to update the list
  • Click here to download the necessary example files.

    test.php

    JavaScript: the call to Event.observe tells the browser to call the init function after the page loads. The init function creates a new sortable list on the listContainer element, setting all divs within it to be sortable and setting the updateList function as a callback whenever the list is updated. This means that when the order of items in the list change, this function will be called with the list element passed as an argument. This function will perform the AJAX request to update the database.

    The updateList function sets a variable for the url used during the AJAX request before it calls Sortable.serialize passing the container ID as an argument to serialise the list to a format such as listContainer[]=5, listContainer[]=7, listContainer[]=2

    The first three items of the list would be the items 5, 7, and 2 and the divs representing these items would have the following ID values: item_5, item_7, and item_2. This serialised list is set in the variable ‘params’.

    Next an AJAX request is opened using Prototype’s Ajax.Request class. It is called with two arguments: the URL and an object with various options. The options include the type of request (POST in this example, parameters to pass the params variable and two functions (onLoading/onLoaded) that handle the showing and hiding of the ‘Updating database…’ div.

    Normally in an AJAX request you would also add a callback for onComplete to handle the response from the server, but in this case the AJAX response doesn’t really matter because it is a one way communication in this demo. In a real application you would have more error handling and would need to correctly handle error conditions.

    At the footer of the file there is a div with the ID ‘containerDiv’ which is the container for our list. Within this is some PHP that loops through an associative array and prints out each list item as a div with ID ‘item_10’ where 10 is the ID for that record in the database.

    request.php

    This file begins by calling session_start() to send the right http headers to prevent the file from being cached. Next it instantiates an object and calls the updateList method passing the listContainer variable from the POST request (containing our serialised list).

    db.inc

    This is a simple db class that connects to the database and has methods to get and update the order of the list. In a ‘real’ application you should have a much cleaner implementation of the database access and would use other DB libraries to connect.

    Scriptaculous list sorting with AJAX callbacks Read More »