Skip to main content

Posts

Showing posts with the label php

Composer in php

For those who are unaware of composer in php, Composer is a tool for dependency management. It allows us to declare the dependent libraries our project needs and installs them in our project. It is inspired by the node's npm and ruby's bundler. So, basically if we have a project that depends on a number of libraries and those libraries depend on other libraries, we declare the libraries we depend on. Composer downloads and installs the required packages in our project. For this, we need a file composer.json that describes the project's dependencies. For e.g. we have used here monolog library to do logging. {     "require": {         "monolog/monolog": "1.2.*"     } }

Detecting the browsing device

We can check the device that is used for browsing. The following code detects if the browsing device is mobile. if (preg_match("/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", strtolower($_SERVER['HTTP_USER_AGENT']))) {  //browsed from mobile device }