Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, May 18, 2014

Calculating colour contrast from hex colour code (php, javascript)

This time I have a nice little snippet to offer you: there is an easy way of calculating contrast from hex colour codes. I needed this on one of my web apps where I wanted to display the background of certain buttons in one colour and wanted the app to automatically calculate if I should set black or white as foreground colour for the button so it's easy to read.

Thursday, August 22, 2013

Prevent form reload (login, shopping cart... etc).

Today I was looking through my draft posts and saw this one about preventing form reload, and this is the note I took at the time: "set session variable to empty at form load, set it to something at successful submit, if session variable set when submit clicked, throw error" - well, yes, that was the first thought about it I found on the net, however, after I continued to look, I found that there is a better, more efficient way to do this:

Sunday, February 17, 2013

Even or odd number validation with PHP

The other day, while I was writing up some PHP code, I ran into a really cool way of identifying if a number is even or odd (refer to the link further down below). I needed it as I looped the creation of a couple of divs and wanted the odd numbered ones to be floated left, the evens to the right.

Friday, July 29, 2011

HTML and PHP includes

I know it's been a long time since I wrote here, but [replace with usual bla-bla], so let me make it up to you guys and give you a nice little hint here.

Usually when I want to build a website quickly and where design or dynamism is not all that important, I use simple HTML instead of PHP as I found it being much quicker to write. However, not being dynamic, a website built in HTML would be very complicated and time consuming to apply any changes to, unless you use a website builder software

Wednesday, June 23, 2010

Embed music with dowload.php file

Scenario: you would like to embed a music file (.mp3 in our example) into your website and also want to make sure that when someone clicks the download link the usual open / save as window opens instead of the browser trying to open the file directly with whatever plugin already installed.

My solution: we'll have to break this down into two parts: one will be the embed script and the other one will be the download link.