Thursday, January 5, 2017

php detect _SERVER['HTTP_USER_AGENT'] is IE 8, 9, 10, 11

<?php
echo $_SERVER['HTTP_USER_AGENT'];exit;
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if(count($matches)<2){
  preg_match('/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
}

if (count($matches)>1){
  //Then we're using IE
  $version = $matches[1];

  switch(true){
    case ($version<=8):
      //IE 8 or under!
 echo '8';
      break;

    case ($version==9 || $version==10):
      //IE9 & IE10!
 echo '9-10';
      break;

    case ($version==11):
      //Version 11!
 echo '11';
      break;

    default:
echo $version;
      //You get the idea
  }
}

mysqli database engine change to MyISAM using php

<?php
$conn = mysqli_connect('localhost','root','');
$dbs = array();
$dbs[] = $_GET['database'];

foreach($dbs as $v){
    mysqli_select_db($conn, $v);
    $q = mysqli_query($conn, 'show tables');
    $tables = array();
    while($r = mysqli_fetch_row($q)){
        $tables[] = $r[0];
    }
$c=0;
    foreach($tables as $t){
        echo "do $v.$t<br>";
        mysqli_query($conn, 'ALTER TABLE `'.$t.'` ENGINE=MyISAM;');
$c++;
    }
echo $c." tables changed.";
}
mysqli_close($conn);