Cross Browser Web Fonts Using @font-face support

Best way to use custom fonts on your site

cross browser web fonts


If you use custom font in your website using @font-face,then it may possible that it will not display fine in some browsers.


This is due to the font-face browser dependency (every browser supports @font-face slightly differently).


for resolving the cross browser web fonts we have to use different font file for different browser.


Here is the link from where we can get a complete kit of a font files.

font-face Kit Generator


It is very simple to use.
Upload your font file (generally with .ttf extension) with [+Add Fonts] button.
Select your option and check agreement check box.
Click on [Download your kit] button.


Here you will get a prepared zip file for the same.
Download that and use according to your need.


Put font file in a folder, give the path of the same in css file.
Use the css and you will found the same result,you want to get.


You also found a specimen/example to use the font-face in the kit.


Basic web fonts syntax

The @font-face rule


First you insert a block in your CSS, describing a web font you want to embed into your page. This information is all wrapped inside a @font-face block

[sourcecode language=”plain”]
@font-face {
  font-family: ‘Abril Fatface Regular’;
  src: url("AbrilFatface-Regular.otf");


Standard font-family declaration


[sourcecode language=”plain”]
h1 {
font-size: 8em;
font-family: ‘Abril Fatface Regular’, sans-serif;


Other @font-face options


[sourcecode language=”plain”]

@font-face {
font-family: ‘Abril Fatface’;
src: url("AbrilFatface.otf");
font-weight: bold;
font-stretch: condensed;
unicode-range: U+0026;



If you want to know why all this works as above, follow Paul Irish’s Bulletproof @font-face syntax.


Use non-standard font in web pages

Use non-standard font in web pages


Normally your website visitors can only see the fonts that are already installed on their system.

So if you use a font(non-standard) that is not installed on site visitor’s computer then his browser will show some other font that is on their computer. That’s why when you are defining a font for an element (such as <span>,<div>) you often specify multiple fonts so that if your preferred font is not available, then CSS(Cascading Style Sheets) file should use the available alternatives.


font-family: verdana, sans-serif;
Here verdana is preferred and sans-serif is alternative.


This can be really annoying if you want to use a nice font in your website.


Conventional way of using custom fonts for headings and logos creating the text in a graphic editor and then using the image file.From the perspective of SEO this is not appropriate solution,you must use text as much as possible.


Now there is a way available in CSS that lets you use custom fonts, downloadable fonts on your website. You can download the font of your preference, let’s say copse_font.ttf, and upload it to your server where your website is hosted.


Then from within your CSS file (or wherever you are defining your styles) you have to refer to that custom font in the following manner.


@font-face {
font-family: copse_font;
src: url(‘copse_font.ttf’);


font-family: copse_font; /* no .ttf */


You can get some free fonts file from here.



There is another option to use custom fonts in your site is via Google API. However, not so many fonts available so far in Google Font Directory.



You can go there by the link below.
Google Web Fonts API


PHP: Access control modifiers

PHP: Access control modifiers


One of the fundamental principles in OOP(Object Oriented Programming) is ‘encapsulation‘. The idea is that you create cleaner and better code, if you restrict access to the data structures (properties) and methods in your objects.


The access modifier is the most important feature of the OOP language and it is used to restrict the function and classes to be accessed. In PHP, there are some keywords representing these access control modifiers. These keywords will be added with PHP classes and its members (methods and variables).


You can restrict access to class properties using ‘access modifiers’. There are mainly 3 access modifiers:
– public
– private
– protected


Public: This variable or method can be used from anywhere in the script.This is the default access modifier.Properties declared as ‘public’ have no access restrictions, meaning anyone can access them.

Note: When you declare a property with the ‘var’ keyword, it is considered ‘public’.


Private: When you declare a property as ‘private’, only the same class can access the property i.e variable or function can only be used by the object it is part of; it cannot be accessed elsewhere


Protected: When a property is declared ‘protected’, only the same class and classes derived from that class can access the property(this can be done using inheritance). We can say variable or function can only be used by the object it is part of, or descendents of that class.


There are some other special keywords you can place before a class, a class function definition, or a class variable to alter the way PHP works with it – here’s are the list, along with what each of them does..


Final: This variable or function cannot be overridden in inherited classes.


Abstract: This function or class cannot be used directly – you must inherit from them first.


Difference between htmlspecialchars and htmlentities

What is the difference between htmlspecialchars and htmlentities PHP functions?



This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.


Some characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made.If you require all HTML character entities to be translated, use htmlentities() instead.


1. htmlspecialchars may be used when there is no need to encode all characters which have their HTML equivalents.


2. htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.


In Short, you can say


htmlspecialchars(): Convert some special characters to HTML entities (Only the most widely used)

htmlentities(): Convert ALL special characters to HTML entities



PHP: Difference between cookies and session

What is the difference between cookies and session?


HTTP is a stateless protocol.
That mean, that treats each request as an independent transaction that is unrelated to any previous request. So, how about the request we want to make frequently, like username or id? As you know, we could store our data in COOKIE. When we store data in COOKIE, the browser will send the cookie data to server for each request. We already could use SESSION for this kind of task. So, what is difference between SESSION and COOKIE?


A cookie is a text-only string that takes a place in the memory of user’s browser. If the lifetime of the cookie is set to be longer than the time user spends at that site, then this string is saved to file for future reference. User could be disabled the cookie in their browser setting.


A session is an object associated with a client connection to the server. it has the ability to carry information related to the client,session values are store in server side not in user’s machine. A session is available as long as the browser is opened. User couldn’t be disabled the session. We could store not only strings but also objects in session.

Session files are deleted automatically by php according to garbage collection settings.


1.The main difference between cookies and sessions is that cookies are stored in the user’s browser(hard disk), and sessions are not,cookies are browser dependent and sessions are not dependent on client’s browser settings


2.A cookie can keep information in the user’s browser until deleted. But Session work instead like a token allowing access and passing information while the user has their browser open.


3.The difference between sessions and cookies is that a session can hold multiple variables or objects, and you don’t have to set cookies for every variable. By default, the session data is stored in a cookie with an expiry date of zero, which means that the session only remains active as long as the browser. When you close the browser, all the stored information is lost. You can modify this behavior by changing the “session.cookie_lifetime” setting in “php.ini” from zero to whatever you want the cookie lifetime to be.


You can get the best! Once you know what each does, you can use a combination of cookies and sessions to make your site work exactly the way you want it to do.


Session vs Cookie or cookies and session in php

Complete guide of cookies and session in php




Many New PHP developers are often confused whether to use sessions or cookies for their websites. Both cookies and sessions have their advantages and drawbacks. PHP developer should first understand the differences between each so that he can choose better option according to need.


Sessions are PHP’s built in method for handing cookies. According to, sessions are “a way to preserve certain data across subsequent accesses.”


Whenever PHP creates a new session, it generates a sessionID (session_id())this session id is then either stored on the user’s computer as a cookie or in some cases, attaches itself to the end of each page’s URL as a query string.The actual information stored is not stored on the user’s computer or client machine.PHP stores the information in the session on the server in some kind of database or a text file( you can see this in phpinfo “session.save_handler“).In the background processes on the server, PHP runs a garbage collecting process that destroys all sessions that have been inactive for twenty-four minutes (in phpinfo “session.gc_maxlifetime“)thus, sessions are a way of storing client information on a server.


Every time on client request (values do not necessarily have to be changed) a session, the garbage collector resets its twenty-four minute countdown for deletion.Thus, a user cannot leave a site and come back in an hour or two (time set in php.ini file) and expect the session to still be alive.In addition, a user’s computer deletes all sessionIDs every time the user closes the browser.Thus, the only real advantage of using sessions is that they allow a PHP developer to hide what information is being stored from the users and hackers.However, hackers can hijack sessions with a cookie grabber, so one cannot argue that sessions are much more secure than cookies.

The only security advantage of sessions is that they hide information; thus, if a website stored a user’s (encrypted) password in a cookie and a hacker somehow obtained the cookie, the hacker could run a password cracker(bad software) on the encrypted password to get it, whereas a session hijacker would have only have access to the account, not the encrypted password.PHP developers should use sessions only for things that require the short-term preservation of data.Overall, sessions serve as a short-term method for preserving data across pages while hiding information from users and hackers.


COOKIE defines cookies as “a mechanism for storing data in the remote browser and thus tracking or identifying return users.”

Cookies maintain a set interval of time even if the user closes the browser (unless of course he clears his cookies or it expire). The only disadvantage to using a cookie is that the information is stored locally on the user’s computer in a text file. Therefore, hackers who use cookie stealer can access the information as well as anyone with physical or remote access to the computer’s files, this can be a security threat. However, a well-coded website prevents cookie grabbers from working, and thus eliminates most of the security threat. However, it is important to keep in mind that users can easily change the value of a cookie, so treat anything inside of a cookie as malicious user input. Therefore, PHP developers should use cookies as a long-term solution to preserve data across pages and sessions.


Overall, sessions serve as temporary information holder that can hide information, whereas cookies serve as both a temporary and long-term information holder. After the difference between sessions and cookies is clear, making the right choice for a website is rather simple. Though sessions may seem easier to use than cookies, never doubt the power and ease of using cookies.


Hope this will help 🙂


Do you want to know a quick answer of differences between session and cookie?