Managing Dependencies with Composer

Composer is a package manager for PHP much like gem is for ruby or npm is for node. It allows you to define libraries that your application depends on and will install them for you as well a their own dependencies. It also includes an autoloader to load classes in both the installed packages as well as your own classes. Installation The easiest way to install composer on a Mac or Linux based OS is to run one of the following commands from a terminal. This will download a file into the current…
Read More →

Building a simple contact form in PHP - Part 5

In of part 4 of Building a simple contact form in PHP we added a CAPCHA field to help reduce spam. In this part we are going to change the sending of the mail to use SMTP by using Swift Mailer, a php mailing library. As we left it our contact form looked like this. Add the SMTP credentials to your configuration file I am using a gmail account as an example. Change the server, port, username, and password to whatever the settings for your email account are. Adding the Swiftmailer library Head…
Read More →

Building a simple contact form in PHP - Part 4

In of part 3 of Building a simple contact form in PHP we added client-side validation to our form. In this part we are going to add a CAPTCHA field to the form in order to reduce spam. We have validation to help prevent blank form submissions but there is still nothing to stop spam bots from sending a bunch of junk posts via some automated script. A common way of reducing spam is by adding a CAPTCHA field to the form. These are those fields with the distorted random characters that you need to…
Read More →

Building a simple contact form in PHP - Part 3

As we last left it in part 2 of Building a simple contact form in PHP we added server-side form validation to our contact form and input filtering to the submitted data before sending out the email. In this part we are going to add some client-side validation to our contact form. This is the contact form as we left it. Why Add Client-Side Validation? It is important to keep in mind that client-side validation doesn't not provide any extra security for your application. Circumventing it is as…
Read More →

Building a simple contact form in PHP - Part 2

In part 1 of Building a simple contact form in PHP we built a simple contact form that sends a notification when the form is posted with the values the user posted. As we discussed at the end of part 1 there are a few problems with our contact form. We are going to work on solving some of those problems. The is what the contact form looked like as we last left it. Adding Form Validation Right now a user is able to submit a blank form and an email will still be sent. We are going to add some…
Read More →

Building a simple contact form in PHP - Part 1

In this series we will be building a simple contact form in php. It will cover sending emails and form validation. Creating the Contact Form We will start with the form itself. Save the following as contact.php We will also add a stylesheet with some basic styles for the form. Save the following as styles.css If you view the page in a browser it should look something like this. Not the prettiest form but this isn't a design tutorial. Feel free to add your own styles. We also will need a page to…
Read More →

Secure Password Hashing with PHP

There is a lot of misinformation and uncertainty on the topic of password storage. There are massive amounts of tutorials and articles recommending all manor of methods of storing passwords. A large number of these are old and using methods that just are up to snuff for todays security standards. Common password storing mistakes Here are some of the most common mistakes make with regards to password hashing. I've been guilty of all of these in the past. MD5 and SHA1 hashing The md5 and sha1 are…
Read More →

Simplifying database interactions with Doctrine DBAL

I previously wrote about switching from the mysql extension to PDO. PDO introduces a number of convenient features beyond the mysql extension such as transactions, prepared statements, and more fetching options. However there are still a few things that are a bit painful. This article will introduce Doctrine DBAL to help alleviate some of these pain points. Doctrine DBAL is a wrapper around PDO. It adds a few conveniences beyond straight PDO as well as a query builder. There are a number of…
Read More →

Moving from mysql_query to PDO

The mysql extension has been marked as deprecated as of php 5.5.0 and will be removed completely in a future version. It is old and not very user friendly. This article will introduce PDO as a replacement. Connecting to a Database Connecting with mysql_connect The mysql_connect function returns a MySQL link identifier if the database connection was successful or FALSE if the connection was not successful. After connecting to the database server the database must be selected before any queries…
Read More →
Copyright © 2022 - Jonathan Bernardi