Posts Tagged ‘php’

How to Integrate an RSS Feed Into Your Site with Simple XML

Saturday, February 9th, 2008

Practically every site today has an RSS feed. Now, you could be like everyone else and simply use this as a way to read information as it’s published.

Or, you could use RSS for what’s intended for - content syndication. With Simple XML, it’s a piece of cake to use an RSS feed to add a list of links to relevant articles on your page.
(more…)

How to Create Multi-Page Forms in PHP, Revisited

Friday, February 8th, 2008

A couple weeks ago, I wrote a short article about how to create a multi-page form.

The simple solution I suggested involved a foreach loop that cycled through the $_POST array and sent every value along in a hidden input element. After a bit of reflection (and some useful comments), I realized there’s a teeny tiny security hole in that approach - so I’ve slightly modified it to close the loophole.
(more…)

How to Create a Random Date in PHP

Thursday, February 7th, 2008

While browsing some forums the other day, I came across this question - “How do I find a random date in PHP?”

This is a pretty simple operation, if we make use of a few built-in PHP functions - time(), strtotime(), and date(). In this article, we’ll see how these three can work together to find a random date within a given range.
(more…)

How to Send E-Mail in PHP: A “Share This” Form

Wednesday, February 6th, 2008

This question comes up a lot in forums - how do you send e-mail in PHP?

There are plenty of reasons you’d want to do this. Perhaps you want to send a newsletter to your users. Or you want people to be able to leave feedback through e-mail. Or you just want your users to be able to e-mail the page (or a link to it) to a friend.

How do we do this? The mail() function.
(more…)

How to Use Custom Stylesheets on a Per Post Basis in Wordpress

Tuesday, February 5th, 2008

Something I struggled with recently was assigning individual style sheets to posts on this Wordpress blog. For example, if I was writing a CSS tutorial I didn’t want to muck up my general stylesheet with a bunch of styles - it’d be nice to write a small stylesheet and attach it only to the specific post that needs it.

Unfortunately, this isn’t a built in function of Wordpress. Fortunately, you can add this functionality with a plugin.
(more…)

Five PHP Coding Mistakes to Avoid

Monday, February 4th, 2008

While browsing through dZone the other day, I stumbled on this article - 40 signs you really are a lousy PHP programmer.

While I don’t agree with all of the author’s points, it’s an interesting list of php coding habits to avoid - but that most of us tend to pick up anyway. Here’s a list of my five biggest pet peeves.
(more…)

Understanding the Difference Between MD5 and Crypt Functions

Saturday, February 2nd, 2008

If you’re working with a user-management system in PHP (or any scripting language), than you’re likely using either the md5() or crypt() function to encode and store the user’s password.

An oft-asked question - and oft-misunderstood - is what is the difference? Is one better than the other?
(more…)

Time Well Spent, Learning Programming

Friday, February 1st, 2008

Browsing through DZone, I stumbled on an interesting illustration - the Programmer’s Food Pyramid.

The Pyramid illustrates the different activities that someone generally engages in while learning to program. While looking at the pyramid, I thought, “Do I do all these things?”
(more…)

How to Create a Random Password for Users

Friday, February 1st, 2008

If you’re working on a user-management system, you may find it useful to be able to create a random password for users.

Some systems generate these initially and have the user log in to set a permanent password. You might also have a “Reset” button, where the script generates a random password and e-mails it to the user.

This quick tutorial will show you how to create an 8 character random password containing a mix of letters and numbers. Or, if you’re impatient, jump straight to the function’s source code
(more…)

How to Use PHP To Dynamically Resize an Image

Wednesday, January 30th, 2008

Screenshot of a Dzone PageOne of the most annoying things about working with images is getting them into the right size. Screenshots start out huge - and you need to resize them to an appropriate size for your website.

Some blogs automatically resize the pictures for you into a thumbnail - like the image to the right. What if you want the image a different size, though? You could allow the browser to resize it for you, or - better yet - write your own php script to resize the image dynamically.
(more…)