Friday, May 25, 2012

How to get Browser data using PHP coding

Sometimes we are in need of browser data to work accordingly,

 For example,
         Name of the Browser, Version,
         To check is Javascript or Cookies enabled in the current Browser?
          etc......

 TO Do this there is a php function named get_browser

Examples:
     PHP Code:
            $browser = get_browser(null, true);                                                                                 
             print_r($browser);

     Output:
           Array                                                                                                                                  
           (
                 [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
                 [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
                  [parent] => Firefox 0.9
                  [platform] => WinXP
                  [browser] => Firefox
                  [version] => 0.9
                  [majorver] => 0
                  [minorver] => 9
                  [cssversion] => 2
                  [frames] => 1
                  [iframes] => 1
                  [tables] => 1
                  [cookies] => 1
                  [backgroundsounds] =>
                  [vbscript] =>
                  [javascript] => 1
                  [javaapplets] => 1
                  [activexcontrols] =>
                  [cdf] =>
                  [aol] =>
                  [beta] => 1
                  [win16] =>
                  [crawler] =>
                  [stripper] =>
                  [wap] =>
                  [netclr] =>
             )

TroubleShooting get_browser

1) If get_browser is not working as excepted

         Step 1) Check whether browscap in installed in your system with the help of If it is installed, phpinfo will show like below 


Else it will look like

        

So if browscap is not installed,
     Go ahead with the following steps to install browscap

            Step 1 : Download php_browscap.ini file from the link http://browsers.garykeith.com/downloads

             Step 2 : Place php_browscap.ini anywhere in the system and register the path of the file in php.ini

      For example:
           Initially php.ini will look like,
              [browscap]
               ; http://www.php.net/manual/en/misc.configuration.php#ini.browscap
               ;browscap = extra/browscap.ini

              We have to modify the above code as 
                 [browscap]
                 ; http://www.php.net/manual/en/misc.configuration.php#ini.browscap
                 browscap = /path/to/php_browscap.ini

               Note: Dont forget to uncomment the browscap line

              Step 3 : Restart Apache i.e service httpd restart
                
 

Wednesday, May 9, 2012

Jquery Examples

Jquery Examples

Thursday, December 22, 2011

Dyanamically add textbox and remove through jquery

$(document).ready(function(){
var counter = 2;
//to add text box
$('#add-textbox').click(function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr('id', 'edit-child-' + counter +'-wrapper');

newTextBoxDiv.after().html('' + '');

newTextBoxDiv.appendTo('#major-id');

counter++;


});

// to remove text box
$('#remove-textbox').click(function () {
counter--;
$('#edit-child-' + counter +'-wrapper').remove();

});

});

Thursday, September 22, 2011

How to show different images in different page using single block

step1:write the block title

step2:write the following php code in body
<?
global $base_url;//give the base url path link "http://www.fando.in"
$url =  $_SERVER['REQUEST_URI'];//it return the  argument of url like "http://www.fando.in/photo" then this while return "photo"
switch($url){
case '/photo':
$img="<img alt='' src = '{$base_url}/sites/default/files/about-us-image.jpg' />";
print $img;
break;
case '/image' :
$img="<img alt='' src = '{$base_url}/sites/default/files/IDW_In_63_0.jpg' />";
print $img;
break;
}
?>
step3:select the "php code " input format.
step4:Show block on specific pages,in that user need to write where this block display
eg:photo
step5:select the region,for proper display block.
eg:leftside,rightside etc

Tuesday, September 20, 2011

target "_blank" opens two windows (Means link open in New window as well as same window)

step1)suppose you add html code in a page of drupal using FCK EDITOR , In that one facebook link is there and after clicking that link,that link open in new window as well as same window.
Here is the code :
<a target="_blank" href="http://www.facebook.com/pages/The-Ideal-School-of-Manhattan/156013431088499">facebook</a>
step2:This problem occurs from "Google Analytic" module

step3:To solve this problem U have three ways:

 1st way->upgrade google analytic module to google_analytics 6.x-3.x-dev(here is link  http://drupal.org/node/807234 )
2nd way->disabled "Track outbound links" in google analytic module(In Site configuration -> google analytic)
3rd way ->Add this patch to the "googleanalytics.js" file
// Track all external links as page views after URL cleanup.
             // Currently required, if click should be tracked as goal.
             _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
+          }
           else {
             // External link clicked.
             _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
@@ -51,10 +56,15 @@
             // that a user can click on the outbound link before the tracking code loads,
             // in which case the event will not be recorded.
             // See http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
         }
       }
+      }
     });
   });
 });
 
MORE REFERENCE VISIT BELOW LINK
        http://drupal.org/node/1057688

 

Friday, July 29, 2011

Add Separate CSS for IE - Drupal 6

There are THREE ways by which we can include css for IE with respective to the versions of IE.

1)From active Themes .info file.
2)From active Themes template file (page.tpl.php).

1)From active Themes .info file. (Eg: Zen theme)

 In Themes .info file, there is a section adds CSS files to your theme, there we can include our custom css file for different IE versions.

Code:

; Set the conditional stylesheets that are processed by IE.

;For all versions of IE browser
conditional-stylesheets[if IE][all][]  = css/ie.css

;For  lte (less than or equal to) IE 7 browser - applies to all versions less than or equal to IE 7 (IE7, IE6, IE5 ,.....)
conditional-stylesheets[if lt IE 7][all][] = css/ie.css

;For  lt (less than) IE 7 browser - applies to all versions less than IE 7 (IE6, IE5 ,.....)
conditional-stylesheets[if lte IE 7][all][] = css/ie.css

;For  gte (greater than or equal to) IE 7 browser - applies to all versions greater than IE 7 (IE7, IE8 , IE9,.....)
conditional-stylesheets[if gte IE 7][all][] = css/ie.css


;For  gt (greater than) IE 7 browser - applies to all versions greater than IE 7 (IE8 , IE9,.....)
conditional-stylesheets[if gt IE 7][all][] = css/ie.css 

 ;For only IE 7 browser - applies to only IE 7
conditional-stylesheets[if IE 7][all][] = css/ie7.css 

For More Information -  Click Here


2)From active Theme template file (page.tpl.php).

 Code to be included in <head> </head> tag.

/*For all IE browsers version less than or equal to IE7*/
<!--[if lte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version less than  IE7*/
<!--[if lt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than or equal to IE7*/
<!--[if gte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than IE7*/
<!--[if gt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For only IE 7 browser - applies to only IE 7*/
<!--[if IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->


/*For all IE browser - applies to all IE versions*/
<!--[if IE]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->