Wednesday 6 July 2011

Detecting Browser with php

  “If you have raced with men on foot  and they have worn you out,  how can you compete with horses? If you stumble in safe country,    how will you manage in the thickets (foods) by the Jordan? "
-Jeremiah 12:5
Ever had problems with rendering your web apps on different browsers and find some inconsistencies in the display? Now this is what I have been through in the recent past. Much of my functions done in AJAX don't work with IE but perform very well with other browsers.

Most writers say that the problem comes when instantiating the object whereas you use ActiveX objects in IE the other browsers use XMLhttpRequest object.

For IE :
var request = new ActiveXObject("Microsoft.XMLHTTP");
 
For others (Safari, Google chrome and Firefox):
var request = new XMLHttpRequest();
Now I have gone through this several occasions and every time something new crops up and make a very crucial decision for my clients to use other browsers other than IE due to its non standardization and their quest to be unique at the expense of my (developer's) time doing two sets of codes for different browsers.

This problem drove me to seek to detect the browser On-page-load and give information to the user on the browser to use. Though using php to do this slows the process other than the client side JavaScript I like the php idea more.

Since I have tested most of my codes with several browsers that are commonly used and the fact that web browser market share for IE is declining see I  chose to detect the IE usage and give information to the user and provide link for download of some of the browsers;

Here is the code:
 <?php
function isie_broswer()
{
    //Gets user's operating system, as well as their browser
   $u_agent = $_SERVER['HTTP_USER_AGENT'];
   //Search the string of the operating system and browser returned to find if its IE
   if(preg_match('/MSIE/i',$u_agent))
    {
       return true;
    }
   else
   {
       return false;
   }
  
}

if(!isie_broswer())
{.....}
else
    {
   ?>
    <div align="center" style="padding-top:20px; padding-bottom:20px;">
    <table height="40" width="80%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FF3333"  class="aligncenter">
      <tr >       
        <td bgcolor="#FFFFFF" class="aligncenter" valign="middle" style="padding-top:10px;">
         <img src="images/icons/exclamation.jpg" width="100" height="100" align="left" >                                      
        This page is not designed for Intenet Explorer.  If you want to see this webpage as intended, please use a standards compliant browser, such as <a href="http://www.google.com/chrome">Google Chrome</a> .OR <a href="http://www.mozilla.com">Mozilla Firefox</a>
     </tr>
    </table>
    </div>
<?php
}
?>

I hope this helps friends like me;

Good day

Tuesday 5 July 2011

The theory of Natural Selection. "Survival of the fittest"- Kingdom

I have been reading and thinking through Charles Darwin's work in the past week.

In his theory "Natural Selection", Charles Darwin brings out a natural fact about the mechanisms of survival. Now the phrase "Survival of the fittest" was coined later to give an explanation on the growth and reproduction of individual species: the strongest of a species would reproduce to the maximum possible number/offspring and  the weak species were are naturally eliminated and therefore no growth in its/their lineage. This generally means that if a species A living side by side with species B under similar conditions, and say the species A is less stronger than B and the conditions continues from good to worse, the species B would survive longer and maybe reproduce more whereas A might reduce in number(natural death) and eventually be extinct. Ref: http://en.wikipedia.org/wiki/Natural_selection,Johnson, Phillip E. . Darwin on Trial, 2nd ed

Now Assume we use the same analogy Darwin used on his study and use it to learn from the text from the bible from:


 Mat 28:19-20 (, baptizing them in the name of the Father and of the Son and of the Holy Spirit,19 Therefore  20 and teaching them to obey everything I have commanded you. And surely I am with you always, to the very end of the age.”)
Go therefore and make: Meaning reproduce. 
 John 15:2  , while every branch that does bear fruit he prunes[a] so that it will be even more fruitful.that bears no fruit He cuts off every branch in me

John 15:5  (5 “I am the vine; you are the branches. If you remain in me and I in you,6 If you do not remain in me, you are like a branch that is thrown away and withers; such branches are picked up, thrown into the fire and burned.7 If you remain in me and my words remain in you, ask whatever you wish, and it will be done for you., showing yourselves to be my disciples.)8 This is to my Father’s glory, that you

Reading through these excerpts of the scriptures and many more and trying to correlate the same with with Darwin's theory. I think if every thing was left to Nature according to theory of Natural selection and God's mercy were not to prevail in his Kingdom many Christians would be extinct by today.

Just take an example of you and answer these questions:
  1. How many people have you led to Christ in the last 6 months?
  2. How many poor kids have you offered water/food/clothing in the last six months?
  3. How many sick people (Not your friends or relatives) have you visited and talked to in the recent past?
  4. How many people have stopped you for help and you've dismissed coz you think they are con-men/women without giving them a chance?
  5. How many times have you gone to church Not to meet with God but friends and to complete your weeks plans?
  6. And many other questions......
Looking at  the above Questions how many are like me? Guilty?
You realize that were God to allow "Survival of the fittest" theory in His Kingdom may Christians would be gone with the wind BUT God.......


Reflect friends