PHP code example of andreaval / cohesion2-library

1. Go to this page and download the library: Download andreaval/cohesion2-library library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andreaval / cohesion2-library example snippets


      $cohesion = new Cohesion2;
      $cohesion->useSSO(false);
      $cohesion->auth();

       use andreaval\Cohesion2\Cohesion2;
      use andreaval\Cohesion2\Cohesion2Exception;
      try{
          $cohesion = new Cohesion2;
          $cohesion->auth();
      }
      catch(Cohesion2Exception $e){
          die($e->getMessage());
      }
      if($cohesion->isAuth()){
          echo 'Utente autenticato: '.$cohesion->username.'<br>';
          echo 'Id SSO: '.$cohesion->id_sso.'<br>';
          echo 'Id Aspnet: '.$cohesion->id_aspnet.'<br>';
          echo 'Profilo: <pre>'.var_export($cohesion->profile,1).'</pre>';
      } 

      $cohesion = new Cohesion2;
      $cohesion->useSAML20(true);
      $cohesion->enableEIDASLogin(); //per abilitare il login eIDAS
      $cohesion->enableSPIDProLogin(['PF','PG','LP']); //per abilitare il login SPID Professionale
      $cohesion->auth();

      echo $cohesion->profile['nome'].' '.$cohesion->profile['cognome'];

      $cohesion = new Cohesion2;
      $cohesion->logout();

      $cohesion = new Cohesion2;
      $cohesion->logoutLocal();

      $cohesion->setAuthRestriction('1,2,3');

      if($cohesion->profile['tipo_autenticazione']!='PW'){
          echo 'OK puoi usare il servizio';
      }
      else echo 'Autenticazione debole non permessa';