Total Pageviews

Sunday, June 23, 2013

Detect Browser in php, User agent detection in php

function detect_mobile()
{
    if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
        return true;

    else
        return false;
}

$mobile = detect_mobile();
if($mobile === true)
{

header("location:mobiledevice/index.php");

}
else
{

echo '<h3>you are looking via system browser</h3>';

/*echo $_SERVER['HTTP_USER_AGENT'];*/

}





Follow kvn_krishna on Twitter

Detect Browser in Javascript, User agent detection in Javascript

<script type="text/javascript">
 var ismobile = navigator.userAgent.match(/(alcatel) | (amoi) | (android) | (avantgo) | (blackberry) | (benq) | (cell) | (cricket) | (docomo) | (elaine) | (htc) | (iemobile) | (iPhone) | (ipad) | (ipaq) | (ipod) | (j2me) | (java) | (midp) | (mini) | (mmp) | (mobi) | (motorola) | (nec-) | (nokia) | (palm) | (panasonic) | (philips) | (phone) | (playbook) | (sagem) | (sharp) | (sie-) | (silk) | (smartphone) | (sony) | (symbian) | (t-mobile) | (telus) | (vodafone) | (wap) | (webos) | (wireless) | (xda) | (xoom) | (zte)/i);

 if(ismobile)
 {

// window.location = 'https://www.google.com.my';
 alert("You are using mobile");

 }
 else
 {

 // window.location = 'https://www.yahoo.com';
 alert("You are using system");


 }
</script>


Follow kvn_krishna on Twitter

Detect Browser in htaccess, User agent detection in htaccess

RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://mobiledomin.com [R=301]

Follow kvn_krishna on Twitter

Tuesday, June 4, 2013

Href click submit jQuery, Simple JQuery validation, Form submit and reset jQuery. Self refresh jQuery



How to submit form with anchor tag/ href/a click in jquery?
Reload and Reset form jquery?
Simple validation in Jquery

 // bind "click" event for links with title="submit"
  $("a#submitcontact").click( function(){
    // it submits the form it is contained within
    $(this).parents("#register-form").submit();
  });
 
  $("#register-form").submit(function() {
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//$("#inline").empty().append('abc');
var address = $("input[name=Email]").val();
var emailError = true;
if($("input[name=Nama]").val() == ''){
$("#inline").empty().append('Please enter your Name.');
$('#Nama').focus();
return false;
}

else if($("textarea[name=Alamat]").val() == ''){
 
$("#inline").empty().append(' Please enter your Alamat');
           
$('#Alamat').focus();
return false;
}

else if($("input[name=Email]").val() == ''){
 
$("#inline").empty().append(' Please enter your E-mail address');
           
$('#Email').focus();
return false;
}
else if(!reg.test(address)) {
//emailError = true;
$("#inline").empty().append('Please enter your valid E-mail address.');
$('#Email').focus();
return false;
}
else if($("input[name=NoTelp]").val() == ''){
$("#inline").empty().append('Please enter your NoTelp.');
                 
$('#NoTelp').focus();
return false;
}

else if($("textarea[name=Pesan]").val() == ''){
 
$("#inline").empty().append(' Please enter your Pesan');
           
$('#Pesan').focus();
return false;
}


else{
                    return true;
                }
           
         });


 $("a#reseter").click( function(){
    // it submits the form it is contained within
//opener.location.reload(true);
window.location.href = "contact.html";
   // $(this).closest('form').find("input[type=text], textarea").val("");
   // $(this).parents("#register-form").reset();
  });


 
});



Follow kvn_krishna on Twitter