PHP – Accessing data send over POSTed AJAX

The more I work with PHP, the crazier it becomes.

I was working on the contact form of my new personal site last week when I decided I would submit it over AJAX to make it all nice and fancy. It would be simple: just nab the input values in JavaScript then POST to the PHP for validation and sending by sending the values though JSON.

Continue reading

PHP – Calculate your age

Back in 2014 I wrote a JavaScript tutorial on calculating your age. Today, we are going to be exploring the same thing but in PHP!

Calculating the difference between two dates is much easier in PHP thanks to the DateTime family of classes introduced to the standard library in PHP 5.2.0. They provide built-in methods for timezones, date comparison, and date difference, just to name a few things. Because they abstract all the hard work for us (like good APIs ought to do), we will be putting them to use in this tutorial. If you are one of those poor souls who have to use an even older version of PHP (and I am so, so sorry about that. I hope you are paid well.), it would not be hard to port the JavaScript tutorial and replace the UTC calls with calls to date() (I recommend using “j”, “n”, and “Y”). You might also require running date_default_timezone_set("UTC"); before that depending on your server configuration.

On to the code! :D

Continue reading

PHP – Abstracting uniqid()‘s more_entropy parameter

This is more of an observation/thoughts post and not a tutorial or analysis, so apologies if it is not in the same style you have grown accustomed to on here. :)

The other day while working with some PHP, I looked up the documentation for the uniqid() function to discover what it did and why this code was using it. At the bottom of the page is the following note:

Note: Under Cygwin, the more_entropy must be set to TRUE for this function to work.

What struck me about this note was the lack of any other environments the more_entropy parameter must be set on for the function to work. It would appear it is only required for Cygwin.

Continue reading

Open source… Discrimination?

Fun fact: this post was initially drafted on 16 October, 2013!

If if I have never made it clear before, I love open source software. Some of the best software around is open source: VLC, FFmpeg, Audacity, LibreOffice, CamStudio, Python, Firefox, the list goes on and on. The world of open source is vast and ever-expanding, thanks in part to large proponents such as GitHub, Bitbucket, and popular open source applications. You never know what you will find in this huge world.

Yet I often see almost a form of discrimination (a word you only hear from me once in a blue moon) against this amazing world. Where, when, and how such a notion came to be I do not know, but it is generally as false as old wives tales. Tell me, has your mother’s back ever been broken by you stepping on a crack in the sidewalk?

Continue reading

CSS – Overqualified or more specific selectors?

How many times have you seen CSS like this?

img.alignleft {
  float: left;
  display: inline;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.25);
}

img.alignright {
  float: right;
  display: inline;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.25);
}

If you were to run this through CSSLint, one of the warnings it throws would be “Disallow overqualified elements”. To quote this CSSLint documentation for this warning:

Continue reading

A new triangle

I speak, of course, of my highly visible triangle logo/icon/thingy. What started out as a quick MS Paint graphic has over time evolved into my personal symbol, identifying anything with it as my own.

As any good marketing plan should do, sometimes a logo needs to be tweaked with corrections or to match current design trends. My triangle has changed nearly year since it was developed in 2012, oddly always occurring around April. It started out as the aforementioned MS Paint version:

Continue reading

The single worst line of code I have written

As much as I would love to think I am the perfect programmer who makes no mistakes and whose code is 100% bug free… I am reminded way too well that I am not all that and make lots of code mistakes. I was reminded by this sad truth ever so clearly while working on some older JavaScript on the 29th of May. After extensive testing and analyzing, I concluded that a single line of code in the script was the single worst line of code I had ever written. Are you ready for it?

Continue reading