Make div appear for only a few users of the site [closed]

1

I wanted to make a div that only appears for some people who access my site, how do I do this?

    
asked by anonymous 14.08.2015 / 23:30

1 answer

3

If for example based on a user being logged in could be done this way:

I split my page into small php files (with pure HTML elements) and check if the user is logged on yes the page will be composed with a logout button if not with login and registration buttons.

session_start();
    if((!isset($_SESSION['email']) == true) and (!isset($_SESSION['pass']) == true)){
            require_once 'components/modals/login-modal.php';
            require_once 'components/modals/create-account-modal.php';
        }else{
            require_once 'components/modals/logout-modal.php';
        }

In this way the divs will be secreted

It is also possible to segregate based on other requirements such as the user's browser:

  <?php
    $useragent = $_SERVER['HTTP_USER_AGENT'];

  if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$useragent,$matched)) {
    $browser_version=$matched[1];
    $browser = 'IE';
  } elseif (preg_match( '|Opera/([0-9].[0-9]{1,2})|',$useragent,$matched)) {
    $browser_version=$matched[1];
    $browser = 'Opera';
  } elseif(preg_match('|Firefox/([0-9\.]+)|',$useragent,$matched)) {
    $browser_version=$matched[1];
    $browser = 'Firefox';
  } elseif(preg_match('|Chrome/([0-9\.]+)|',$useragent,$matched)) {
    $browser_version=$matched[1];
    $browser = 'Chrome';
  } elseif(preg_match('|Safari/([0-9\.]+)|',$useragent,$matched)) {
    $browser_version=$matched[1];
    $browser = 'Safari';
  } else {
    $browser_version = 0;
    $browser= 'other';
  }
?>

<html>
    <head>
        <title></title>
    </head>
    <body>
         <?php 
              if($browser == 'Safari'){
                  echo '<span id="#internal">Safari</span>';
              }else{
                  echo '<span>Outro navegador</span>';
              }
         ?>
    </body>
</html>

Based on the string contained in $_SERVER['HTTP_USER_AGENT'] (Super Global) it is possible to identify the Browser, Version and even in some cases by comparing strings.

    
14.08.2015 / 23:34