Category Archives: Web Development - Page 2

How to generate passwords for .htpasswd using PHP

In my earlier post about .htaccess I had described about authentication using .htaccess and command to generate .htpasswd file. However, when we want to add passwords for many users that method will take too long, since we will have to add passwords for each user one at a time. However, there is an easier way to generate the .htpasswd file using PHP. In this post I will show the different algorithms which can be used to generate the .htpasswd file.
Read more »

How to create Triangles using CSS

Many times we come across cases where we want to have triangles, arrows or simple shapes on a site. Usually we use images to add arrows or triangles. However, this can be easily achieved by just using CSS and no need of images at all. In this post we will see how to easily we can create triangles and a few other designs using CSS.

The borders in a browser are drawn at angles, so we can use this technique to create triangle. To create a triangle we will set the border-width value for the side in which we need the arrow. Then, we will set that side’s border color and make all other sides transparent. Also, we set the width and height of the element to 0.
Read more »

How to apply a function to every array element in PHP

I often come across situations in which I need to apply some function to every element of an array in PHP. For example, to sanitize the user input, function like htmlentities can be used. We can easily use this function on a single variable or a single dimension array by simply applying the function or doing a foreach loop respectively. However, to do that on a multi-dimensional array is not very easy using foreach loop. In this article I will discuss the various methods we can use to apply the htmlentities function to a single variable and different types of arrays. The methods that I will discuss can be used to apply any default PHP function or any user defined function to every element of an array.

Read more »

Get various parts of URL using JavaScript

Recently I wanted to get a domain name of the page on which I was currently on. I was trying to parse the entire URL of the page and then parse it using regular expressions etc. to get the domain name. I was able to get the required information using this method, but then I thought that this is something for which there should be an easier way, and indeed there is an easier way.

We can use the Location Object to get all the various parts of the URL. (e.g. window.location.href to get the entire URL)

Note: There is no public standard that applies to the location object, but all major browsers support it.
Read more »

Parts of URL

We see so many URLs everyday, but do we know what are the parts of an URL, what does each part means? In this post I will discuss the various parts of the URL.

An URL may consists of as many as 6 parts. The different parts of the URL are:

scheme://domain:port/path?query_string#fragment_id

Some people refer to the parts as:

protocol://hostname:port/pathname?search#hash

Read more »