$(document).ready(function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); });

Tuesday, December 23, 2014

Get device details in PHP


Get device detail in PHP


Been using PHP for sometime and now working on mobile domain? The first hurdle you must have faced is 'how to determine the device type in PHP', unless you used HTACCESS for that, which isn't the right approach.
So, here I'm writing a class that will get you pretty much information about the device. You can get more by processing the USER_AGENT string!

<?php
class Detect
{
 public static function systemInfo()
 {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $os_platform    = "Unknown OS Platform";
    $os_array       = array('/windows phone 8/i'    =>  'Windows Phone 8',
                            '/windows phone os 7/i' =>  'Windows Phone 7',
                            '/windows nt 6.3/i'     =>  'Windows 8.1',
                            '/windows nt 6.2/i'     =>  'Windows 8',
                            '/windows nt 6.1/i'     =>  'Windows 7',
                            '/windows nt 6.0/i'     =>  'Windows Vista',
                            '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                            '/windows nt 5.1/i'     =>  'Windows XP',
                            '/windows xp/i'         =>  'Windows XP',
                            '/windows nt 5.0/i'     =>  'Windows 2000',
                            '/windows me/i'         =>  'Windows ME',
                            '/win98/i'              =>  'Windows 98',
                            '/win95/i'              =>  'Windows 95',
                            '/win16/i'              =>  'Windows 3.11',
                            '/macintosh|mac os x/i' =>  'Mac OS X',
                            '/mac_powerpc/i'        =>  'Mac OS 9',
                            '/linux/i'              =>  'Linux',
                            '/ubuntu/i'             =>  'Ubuntu',
                            '/iphone/i'             =>  'iPhone',
                            '/ipod/i'               =>  'iPod',
                            '/ipad/i'               =>  'iPad',
                            '/android/i'            =>  'Android',
                            '/blackberry/i'         =>  'BlackBerry',
                            '/webos/i'              =>  'Mobile');
    $found = false;
    $addr = new RemoteAddress;
    $device = '';
    foreach ($os_array as $regex => $value) 
    { 
        if($found)
         break;
        else if (preg_match($regex, $user_agent)) 
        {
            $os_platform    =   $value;
            $device = !preg_match('/(windows|mac|linux|ubuntu)/i',$os_platform)
                      ?'MOBILE':(preg_match('/phone/i', $os_platform)?'MOBILE':'SYSTEM');
        }
    }
    $device = !$device? 'SYSTEM':$device;
    return array('os'=>$os_platform,'device'=>$device);
 }

 public static function browser() 
 {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];

    $browser        =   "Unknown Browser";

    $browser_array  = array('/msie/i'       =>  'Internet Explorer',
                            '/firefox/i'    =>  'Firefox',
                            '/safari/i'     =>  'Safari',
                            '/chrome/i'     =>  'Chrome',
                            '/opera/i'      =>  'Opera',
                            '/netscape/i'   =>  'Netscape',
                            '/maxthon/i'    =>  'Maxthon',
                            '/konqueror/i'  =>  'Konqueror',
                            '/mobile/i'     =>  'Handheld Browser');

    foreach ($browser_array as $regex => $value) 
    { 
        if($found)
         break;
        else if (preg_match($regex, $user_agent,$result)) 
        {
            $browser    =   $value;
        }
    }
    return $browser;
 }
}
Now, you can use it like this: 
$detail = Detect::systemInfo();
to check if it's a mobile, you can use,  

if($detect['device']=='MOBILE')
{
/* Your code for mobile devices */ 
}
else 
{
 /* Your code for desktop systems */ 
}

Tuesday, September 2, 2014

Joomla 1.5, broken/ dead links removal

Permanent fix for Joomla (1.5) dead links
Hi,
This one project I've been working on, it's based on Joomla 1.5 and it's pretty messed up with most of the code having coded in core. So, having a walk through any upcoming issues is really messy and boring.
I was reported by the SEO team that I had about 2000 broken/ dead links on my site. When I checked through, they were the 404 Pages. I told that, "that's why 404 pages are!.. to tell you that this link doesn't exist on this site..!" but then they told me, it's going to affect badly Google organic search of my site and hence I had to remove those dead links anyway!
I had no idea what to do. So, I began with what I always do when I've got nothing to start with... hey, no, I didn't sit up to pray to god! I just opened google and described my problem. So, I got few links which I would like to share with you:
How to Resolve Broken Website Links in Joomla 2.5? | OGO Sense
Joomla SEF Menu Links Incorrect 404 Errors 
However, these links didn't fix my problem but gave me an insight. 
I had the list of 404 URLs but I didn't know what to do; the SEO team had asked me to delete them, but how could you delete something that doesn't even exist! (However, it did, in  jos_redirection  table but I was afraid if deleting any of them may raise further issues). Create a  301  redirect  request for 2000+ URLs was a mess. So, what I did was:
1. I created an Excel file containing all those URLs.
2. I read that file into an array.
3. I checked if $_SERVER['REQUEST_URI'] was in_array  containing list of URLs. If it did, I simply redirected the request to homepage using header('Location:homepage');  
4. Then I checked at www.brokenlinkcheck.com and voila, it didn't report those links then!
I hope this helped you. Feel free to comment or suggest.


Friday, April 4, 2014

Free Projects


Hello there. I'm posting few projects here which I had developed in course of my engineering. Feel free to use it. Just don't misuse it. And if you feel thankful, don't forget to mention credits. Enjoy!
PS: For any queries, drop your comments, I'll reply back ASAP.


1. Free English to Hindi Dictionary (Menu based GUI Project in C)

This project was made in C programming language using graphics. This has a major disadvantage that I won't run on OS other than Windows XP. However, since it uses GUI (mouse pointer; menu based) to interact with the application, it is good enough to be presented for purposes like Final year/ third year projects of engineering courses.
Download the zip file to your local system and extract it. Now, run AHED.EXE

PS: More links will be shared soon. AND, USE CODES ON YOUR OWN RISK.

Contact Me

Name

Email *

Message *