0
Welcome Guest! Login
0 items Join Now

if then browser php question

  • if then browser php question

    Posted 18 years 1 month ago
    • I need to find a way to include an if then statement for a module to display a certain way if IE6/7 then firefox. so my question is how do I get the browser info to a variable then an if then statement like

      If broswer = ie6 or ie7

      echo 'something here';

      else echo 'something here';

      Can anyone help with this.

      FYI the reason is my login module is not displaying correctly because IE6/7 need the float:left command and firefox doesnt..

      Doug
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Hi,

      Do this:
      <!--[if lte IE 7]>
      <link href="<?php echo $mosConfig_live_site;?>/templates/<?php echo $mainframe->getTemplate(); ?>/css/template_ie7.css" rel="stylesheet" type="text/css" />
      <![endif]-->
       
      <!--[if lte IE 6]>
      <link href="<?php echo $mosConfig_live_site;?>/templates/<?php echo $mainframe->getTemplate(); ?>/css/template_ie6.css" rel="stylesheet" type="text/css" />
      <![endif]-->

      If you place the css file in the css folder of your template then it will be included. if you want the same for both use the same file in each statement.

      This goes in your head area of the template index.php file after any other CSS statements. It has to be last.

      Mike
    • www.jikometrix.net
      JIKOmetrix - Reliable web hosting
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Mike,

      I am not trying to call a CSS file, but enter this into Community builders php file to display the login different in IE6/7 then firefox. What does if lte IE 7 do? what is lte? How does php know the browser is IE 7?
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Hi,

      To be honest it is Joomla-eese or joom-ilian? Either way it works to detect the browser type and allows you to load a specific CSS file as a result. I know how to do an IF statement in PHP with an OR however I do not know what variable Joomla sets when it determines IE7 or IE6. With that said here is Hack backward way to get what you want:
      <!--[if lte IE 7]>
      <?php $set_custom_IE7_flag = 1;?>
      <![endif]-->
       
      <!--[if lte IE 6]>
      <?php $set_custom_IE6_flag = 1;?>
      <![endif]-->

      Now in your CB file add this:
      if ( $set_custom_IE7_flag == 1 ) {
      &nbsp;  echo 'soemthing';
      }
       
      if ( $set_custom_IE6_flag == 1 ) {
      &nbsp;  echo 'soemthing else';
      }

      That should work. You may have to declare them as global but post back if that does not work.

      MIke
    • Last Edit: 18 years 1 month ago by Mike Brandonisio.
    • www.jikometrix.net
      JIKOmetrix - Reliable web hosting
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Did not work....

      code before changing

      if ( !$horizontal ) {
      $preDiv = '<div style="float:left; text-align:center; margin:0px auto;"> '
      . '<div style="margin:auto; align:center; width:100%;"> '
      . '<div style="display:table; margin:auto; align:center;';
      $postDiv = "</div></div></div>\n";
      }


      code after change

      if ( !$horizontal ) {if ( $set_custom_IE7_flag == 1 ) {
      $preDiv = '<div style="float:left; text-align:center; margin:0px auto;"> '
      . '<div style="margin:auto; align:center; width:100%;"> '
      . '<div style="display:table; margin:auto; align:center;';
      $postDiv = "</div></div></div>\n";
      } if ( $set_custom_IE6_flag == 1 ) {
      $preDiv = '<div style="float:left; text-align:center; margin:0px auto;"> '
      . '<div style="margin:auto; align:center; width:100%;"> '
      . '<div style="display:table; margin:auto; align:center;';
      $postDiv = "</div></div></div>\n";
      }

      $preDiv = '<div style="text-align:center; margin:0px auto;"> '
      . '<div style="margin:auto; align:center; width:100%;"> '
      . '<div style="display:table; margin:auto; align:center;';
      $postDiv = "</div></div></div>\n";
      }
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Hi,

      You have the normal one at the end it needs to be first since it will rewrite the VAR's that were set by the IF statements:
      if ( !$horizontal ) {
       
           $preDiv = '<div style="text-align:center; margin:0px auto;"> '
                . '<div style="margin:auto; align:center; width:100%;"> '
                . '<div style="display:table; margin:auto; align:center;';
           $postDiv = "</div></div></div>\n"; 
       
           if ( $set_custom_IE7_flag == 1 ) {
                          $preDiv = '<div style="float:left; text-align:center; margin:0px auto;"> '
                                         . '<div style="margin:auto; align:center; width:100%;"> '
                                         . '<div style="display:table; margin:auto; align:center;';
                          $postDiv = "</div></div></div>\n";
           }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
       
           if ( $set_custom_IE6_flag == 1 ) {
                          &nbsp;  $preDiv = '<div style="float:left; text-align:center; margin:0px auto;"> '
                                         . '<div style="margin:auto; align:center; width:100%;"> '
                                         . '<div style="display:table; margin:auto; align:center;';
                &nbsp;            $postDiv = "</div></div></div>\n";
           }
      }

      Try that.

      Mike
    • www.jikometrix.net
      JIKOmetrix - Reliable web hosting
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Mike,

      That did not work either.. How does the $set_custom_IE7_flag get set to 1? It seems like the flag is 0 (false?) when using IE7 but this is a complete guess, just saying that it cant be 1 or the code would be good for IE7..Any other ideas on what it could be, seems like you are really close to cracking something I have worked on for months.

      Doug
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Hi,

      I've been poking around and found that condition statements we were testing with are CSS conditions. I found this link:
      www.quirksmode.org/css/condcom.html

      I started looking in the Joomla code and found in file includes/joomla.php on line 1429 where Joomla detects what browser the user has. the finction starts aounr line 1408. Here is the beginning:

      /**
      * Detects a 'visit'
      *
      * This function updates the agent and domain table hits for a particular
      * visitor. The user agent is recorded/incremented if this is the first visit.
      * A cookie is set to mark the first visit.
      */
      function detect() {

      So any Var created in the function is not global or accessable outside of the function. Maybe if we made the $browser variable global you could call it in an IF statement to determine if the browser is MSIE. I'd hav e to mess more with this to figure it out. Canyou run with this?

      Mike
    • www.jikometrix.net
      JIKOmetrix - Reliable web hosting
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Mike,

      I just noticed the following code in your response

      <!--[if lte IE 7]>
      <?php $set_custom_IE7_flag = 1;?>
      <![endif]-->

      <!--[if lte IE 6]>
      <?php $set_custom_IE6_flag = 1;?>
      <![endif]-->

      What file was this supposed to be entered into?

      Cb login php file?

      This might be my issue as this variable is not in the code to trigger the 1 state.
  • Re: if then browser php question

    Posted 18 years 1 month ago
    • Hi,

      it was supposed to go into the index.php of his template. However, This is CSS logic and the php code will be set regardles of the CSS logic since CSS login is determined by the browser not the server. My mistake.

      I'm still not sure how to help him though.

      Mike
    • www.jikometrix.net
      JIKOmetrix - Reliable web hosting

Time to create page: 0.072 seconds