Options +FollowSymLinks -MultiViews 
RewriteEngine on
# RewriteLog "/var/log/apache2/rewrite.log"
# RewriteLogLevel 3
##----------------300---------------------
Redirect "/track300.gif" "/track.gif"
Redirect 301 "/track301.gif" "/track.gif"
#Redirect 301 "^/track301.gif" "/track.gif"
Redirect 302 "/track302.gif" "/track.gif"
Redirect 303 "/track303.gif" "/track.gif"
#RewriteRule    "^/track300\.gif$"  "track.gif"  [R]
##----------------400---------------------
ErrorDocument 404 /404.html
ErrorDocument 401 /LogIn.php
# ErrorDocument 500 /
##---------------Restrict-access----------
# IndexIgnore *.jpg *.png
# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# order allow,deny
# deny from 123.45.6.7
# deny from 012.34.5.
# allow from all
# IP block 012.34.5.
# Order allow,deny
# Allow from all
##--------------prevent-hotlink-----------
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?analisi.ad.mediamond.it/.*$ [NC]
RewriteRule \.(jpg|png|css)$ - [F]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
##---------------prevent-force-csv--------#error
# 
			    #   ForceType application/octet-stream
			    #   Header set Content-Disposition attachment
			    # 
##-------------SEO------------------------
#RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1 
#RewriteRule ^widgets/(.*)/page(.*)\.php /widgets.php?cat=$1&page=$2 [L]
			    
				RewriteRule ^mod_rewrite\.html$ / [L]
				RewriteRule ^mod_rewrite\.php$ / [L]
				RewriteCond %{REQUEST_URI} /+[^\.]+$
				RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
				# RewriteCond %{THE_REQUEST} ^.*/index.php
				# RewriteRule ^(.*)index.php$ http://analisi.ad.mediamond.it/$1 [R=301,L]
				# Redirect 301 /home http://analisi.ad.mediamond.it 
				RewriteCond %{HTTP_HOST} !^analisi.ad.mediamond.it$ [NC]
				RewriteRule (.*) http://analisi.ad.mediamond.it/$1 [R=301,L]
				RewriteRule ^(([^/]+/)*)index\.php http://analisi.ad.mediamond.it/$1 [R=301,L]
				#RewriteRule ^olddir/(.*) http://www.example.com/newdir/$1 [R=301,L]
				# Get the requested URI, query string and hostname.
				RewriteCond %{REQUEST_URI} ^(/[^?]*)([?].*)?$
				RewriteRule . - [E=myUri:%1,E=myQuery:%2]
				# Replace hmtl, htlm, and thml file extensions with html extension.
				RewriteCond %{ENV:myUri} ^(.*)[.,](hmtl|htlm|thml)$ [NC]
				RewriteRule . - [E=myRedirect:yes,E=myUri:%1.html]
				# Replace comma(s) or multiple filetype delimiter periods in the url
				# with a single period.
				RewriteCond %{ENV:myUri} ^(.*)([,.]{2,}|,)((s?html?|php[1-9]?|aspx?|pdf|xls).*)$ [NC]
				RewriteRule . - [E=myRedirect:yes,E=myUri:%1.%3]
				# Remove invalid trailing characters
				RewriteCond %{ENV:myUri} ^([/0-9a-z._\-]*)[^/0-9a-z._\-] [NC]
				RewriteRule . - [E=myRedirect:yes,E=myUri:%1]
				# Remove trailing punctutation
				RewriteCond %{ENV:myUri} ^(.*)[._\-]+$
				RewriteRule . - [E=myRedirect:yes,E=myUri:%1]
				# Do the external 301 redirect only if needed and the resource exists
				# at the corrected URI.
				RewriteCond %{ENV:myRedirect} ^yes$ [NC]
				RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -f [OR]
				RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -d
				RewriteRule . http://analisi.ad.mediamond.it%{ENV:myUri}%{ENV:myQuery} [R=301,L]
				RewriteRule ^index.html$ index.php
			    
##---------------cache-------------------#error
# # 1 WEEK
# 
				# Header set Cache-Control "max-age=604800, public"
				# 
# # 2 DAYS
# 
				# Header set Cache-Control "max-age=172800, proxy-revalidate"
				# 
# # 1 MIN
# 
				# Header set Cache-Control "max-age=60, private, proxy-revalidate"
				# 
##http://www.catswhocode.com/blog/10-htaccess-snippets-to-optimize-your-website
##-------------spam-on-mail-form----------
			    
				RewriteEngine On
				RewriteCond %{REQUEST_METHOD} POST
				RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
				RewriteCond %{HTTP_REFERER} !.*analisi.ad.mediamond.it.* [OR]
				RewriteCond %{HTTP_USER_AGENT} ^$
				RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
			    
##-------------html5-video----------------
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# AddType video/ogg .ogv
# AddType video/ogg .ogg
# AddType video/mp4 .mp4
# AddType video/webm .webm
# AddType application/x-shockwave-flash swf
##------------https-redirect-------------------
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*) https://%{HTTP_HOST}/$1
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]
##--------------bot----------------------------
RewriteCond %{HTTP_USER_AGENT} MJ12bot
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} 80legs [NC]
RewriteRule ^ - [F]
##--------------svg-support--------------------
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
AddType text/x-component .htc
DirectoryIndex index.php
##-------------php-session---------------------
			     
				php_value memory_limit 512M 
				php_value max_execution_time 18000 
				php_flag magic_quotes_gpc off 
				php_flag session.auto_start off 
				php_flag suhosin.session.cryptua off 
				php_flag zend.ze1_compatibility_mode Off 
			    
##### mod_deflate compresses your output to lower the file size being sent to the client #####
# ##--------------------gzip--------------------------- 
# 
				#  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
				#  BrowserMatch ^Mozilla/4 gzip-only-text/html
				#  BrowserMatch ^Mozilla/4\.0[678] no-gzip
				#  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
				#  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
				#  Header append Vary User-Agent env=!dont-vary
				#  php_flag zlib.output_compression on
				# 
# 
				#  SetOutputFilter DEFLATE 
				# 
# 
				#  SSLOptions StdEnvVars 
				# 
# ##### Header Directives #####
			    
				Header unset ETag
				Header unset Last-Modified
			    
# ##### disable POST processing to prevent breaking image upload #####
			     
				SecFilterEngine Off 
				SecFilterScanPOST Off
			     
# ##### Served files compression on Apache for improved site speed #####
# 
				#  AddOutputFilterByType DEFLATE text/plain
				#  AddOutputFilterByType DEFLATE text/html
				#  AddOutputFilterByType DEFLATE text/xml
				#  AddOutputFilterByType DEFLATE text/css
				#  AddOutputFilterByType DEFLATE application/xml
				#  AddOutputFilterByType DEFLATE application/xhtml+xml
				#  AddOutputFilterByType DEFLATE application/rss+xml
				#  AddOutputFilterByType DEFLATE application/javascript
				#  AddOutputFilterByType DEFLATE application/x-javascript
				#  BrowserMatch ^Mozilla/4 gzip-only-text/html
				#  BrowserMatch ^Mozilla/4\.0[678] no-gzip
				#  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
				#  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
				#  Header append Vary User-Agent env=!dont-vary
				# 
# ##### Improve site speed through Mod gzip and caching #####
			    
				mod_gzip_on Yes
				mod_gzip_dechunk Yes
				mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
				mod_gzip_item_include handler ^cgi-script$
				mod_gzip_item_include mime ^text/.*
				mod_gzip_item_include mime ^application/x-javascript.*
				mod_gzip_item_exclude mime ^image/.*
				mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
			    
# ##### Default expires headers for all file types  #####
# ##### Not recommended for development environment #####
# 
				#  ExpiresActive On
				#  ExpiresDefault "access plus 1 seconds"
				#  ExpiresByType text/html "access plus 1 seconds"
				#  ExpiresByType image/gif "access plus 2592000 seconds"
				#  ExpiresByType image/jpeg "access plus 2592000 seconds"
				#  ExpiresByType image/png "access plus 2592000 seconds"
				#  ExpiresByType text/css "access plus 604800 seconds"
				#  ExpiresByType text/javascript "access plus 216000 seconds"
				#  ExpiresByType application/x-javascript "access plus 216000 seconds"
				#  
# ##### Mime Type Caching Magento #####
# 
				#  ##### AUDIO #####
				#     AddType audio/mp4 m4a f4a f4b
				#     AddType audio/ogg oga ogg
				#    ##### JAVASCRIPT #####
				#     # Normalize to standard type (it's sniffed in IE anyways):
				#     # http://tools.ietf.org/html/rfc4329#section-7.2
				#     AddType application/javascript js jsonp
				#     AddType application/json json
				#    ##### VIDEO #####
				#     AddType video/mp4                                   mp4 m4v f4v f4p
				#     AddType video/ogg                                   ogv
				#     AddType video/webm                                  webm
				#     AddType video/x-flv                                 flv
				#    ##### WEB FONTS #####
				#     AddType application/font-woff                       woff
				#     AddType application/vnd.ms-fontobject               eot
				#     ##### Browsers usually ignore the font MIME types #####
				#     ##### and sniff the content, however, Chrome shows #####
				#     ##### a warning if other MIME types are used for #####
				#  ##### the following fonts. #####
				#     AddType application/x-font-ttf                      ttc ttf
				#     AddType font/opentype                               otf
				#    ##### OTHER #####
				#     AddType application/octet-stream                    safariextz
				#     AddType application/x-chrome-extension              crx
				#     AddType application/x-opera-extension               oex
				#     AddType application/x-shockwave-flash               swf
				#     AddType application/x-web-app-manifest+json         webapp
				#     AddType application/x-xpinstall                     xpi
				#     AddType application/xml                             atom rdf rss xml
				#     AddType image/webp                                  webp
				#     AddType image/x-icon                                ico
				#     AddType text/cache-manifest                         appcache manifest
				#     AddType text/vtt                                    vtt
				#     AddType text/x-component                            htc
				#     AddType text/x-vcard                                vcf
				# 
			    
				AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
			    
##### Disable ETags http://developer.yahoo.com/performance/rules.html#etags #####
 FileETag None
##### Prevent character encoding issues from server overrides #####
#AddDefaultCharset Off
AddDefaultCharset UTF-8
			

Apache .htaccess


include("configxxxxxx.php");
class AdminSql{
  // controllo sulle connessioni attive
  private $attiva = false;
  private $db = false;
  // funzione per la connessione a MySQL
  public function DbConnect($db_host,$db_user,$db_password,$db_name){
    if(!$this->attiva){
      // connecting to db
      $this->db = mysqli_connect($db_host, $db_user, $db_password);
	if ($this->db == FALSE){
      	die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
      	// die (mysqli_error($this->db));
      }
      mysqli_select_db($this->db,$db_name) or die (mysqli_error($this->db));
    }
    else {
      return true;
    }
  }
  // funzione per la chiusura della connessione
  public function DbDisc(){
    if($this->attiva){
      if(mysqli_close($this->db)){
  	$this->attiva = false;
  	return true;
      }
      else{
  	return false;
      }
    }
  }
  //funzione per l'esecuzione delle query
  public function DbQuery($query){
    if(isset($this->attiva)){
        $sql = mysqli_query($this->db,$query) or die (mysqli_error($this->db));
      return $sql;
    }
    else{
      return false;
    }
  }
  //funzione per l'inserimento dei dati in tabella
  public function DbInsert($t,$v,$r = null){
    if(isset($this->attiva)){
  	$istruzione = 'INSERT INTO '.$t;
  	if($r != null){
  	    $istruzione .= ' ('.$r.')';
  	  }
  	for($i = 0; $i < count($v); $i++){
  	    if(is_string($v[$i]))
  	      $v[$i] = '"'.$v[$i].'"';
  	  }
  	$v = implode(',',$v);
  	$istruzione .= ' VALUES ('.$v.')';
  	$query = mysqli_query($this->db,$istruzione) or die (mysqli_error($this->db));
      }else{
      return false;
    }
  }
  // funzione per l'estrazione dei record
  public function DbFetch($risultato){
    if(isset($this->attiva)){
  	$r = mysqli_fetch_object($risultato);
  	return $r;
      }else{
      return false;
    }
  }
  public function DbRow($query){
      $result = $this->db->query($query);
      $rows = array();
      while($row = $result->fetch_array(MYSQLI_NUM)){//MYSQLI_ASSOC,MYSQLI_BOTH
          $rows[] = $row;
      }
      $result->free();
      return $rows;
  }    
  // funzione per la creazione di anteprime dei testi
  public function DbPreview($post, $offset, $collegamento) {
    return (count($anteprima = explode(" ", $post)) > $offset) ? implode(" ", array_slice($anteprima, 0, $offset)) . $collegamento : $post;
  }
  // funzione per la formattazione della data
  public function format_data($d){
    $vet = explode("-", $d);
    $df = $vet[2]."-".$vet[1]."-".$vet[0];
    // converte la data in timestamp
    //  $vet = strtotime($d);
    // converte il timestamp della variabile $vet
    // in data formattata
    //$df = strftime('%d-%m-%Y', $vet);
    return $df;
  }
}
			

sql connector

php sql connector class


/* ini_set('display_errors', 1);
 * ini_set('display_startup_errors', 1);
 * error_reporting(E_ALL);*/
session_start();
include("AdminFuncSql.php");
function encGrp($grpS){
    return crypt((string)$grpS,base64_encode((string)$grpS));
}
function Priv($grpA){
    $inactive = 600;
    ini_set('session.gc_maxlifetime',3600);
    session_set_cookie_params(3600);
    $_SESSION['ref_page'] = $_SERVER['REQUEST_URI'];
    $cookStr = $_COOKIE['intertino_id'];
    $logCook = $cookStr != '';
    $logSess = isset($_SESSION['login']);
    if(sizeof($grpA)==0){
	if($logCook){return 1;}
	if($logSess){return 1;}
	header("Location: LogIn.php");
    }
    if(!$logCook or !$logSess){header("Location: LogIn.php");}
    $enc = '';
    if($logCook){$enc = substr($cookStr,strpos($cookStr,'_')+1);}
    else{$enc=$_SESSION['group'];}
    $Nm = 0;
    foreach($grpA as $r){
	$pr = encGrp($r);
	preg_match('/'.$pr.'/',$enc,$matches,PREG_OFFSET_CAPTURE,0);
	$Nm = $Nm + sizeof($matches);
    }
    if($Nm==0){//header("Location: " . $ref_page);
	echo "

View not allowed to user

"; echo '

log in with a different user: log out

'; exit(); } /* if(isset($_SESSION['timeout']) ) { * $session_life = time() - $_SESSION['start']; * if($session_life > $inactive) * { session_destroy(); header("Location: LogOut.php"); } * }*/ $_SESSION['timeout'] = time(); } function isPriv(){ $cookStr = $_COOKIE['intertino_id']; $logCook = $cookStr != ''; $logSess = isset($_SESSION['login']); if(!$logCook or !$logSess){return 0;} $enc = ''; if($logCook){$enc = substr($cookStr,strpos($cookStr,'_')+1);} else{$enc = $_SESSION['group'];} if($enc == 'bWO8P1G.ddcEs'){return 1;} return 0; }

log-in utilities

functions for a db check in and cookie authentification


function callbackF($data){
    //$json = json_encode(array_values($data));
    $json = json_encode($data);
    //json_encode(array_values($sortedArray),JSON_FORCE_OBJECT);
    if(array_key_exists('callback', $_GET)){
	header('Content-Type: text/javascript; charset=utf8');
	header('Access-Control-Allow-Origin: http://www.example.com/');
	header('Access-Control-Max-Age: 3628800');
	header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
	$callback = $_GET['callback'];
	echo $callback.'('.$json.');';
    }else{
	header('Content-Type: application/json; charset=utf8');
	echo $json;
    }
    # JSON if no callback
    // if( ! isset($_GET['callback']))
    //     exit($json);
    # JSONP if valid callback
    // if(is_valid_callback($_GET['callback']))
    //     exit("{$_GET['callback']}($json)");
    # Otherwise, bad request
    //header('status: 400 Bad Request', true, 400);
}
			

calback functions

returns a callback function for a front - back end call


function LogIn(){
		session_start();
		$ref_page = $_SESSION['ref_page'];
		if($ref_page=="LogIn.php" || $ref_page==""){
		    $ref_page="index.php";
		}
		if (isset($_SESSION['login'])){
		    header("Location: " . $ref_page);
		}
		echo '

Reporting server:
login form:

Username:

Password:

'; session_start(); $ref_page = $_SESSION['ref_page']; if($ref_page=="LogIn.php" || $ref_page==""){ $ref_page="index.php"; } if (isset($_SESSION['login'])){ header("Location: " . $ref_page); }

Reporting server:
login form:

Username:

Password:

include("lib/AdminFuncSql.php"); if(isset($_POST['submit']) && (trim($_POST['submit']) == "Login")){ if( !isset($_POST['username']) || $_POST['username']=="" ){ echo "username missing.\n"; } if( !isset($_POST['password']) || $_POST['password'] ==""){ echo "password missing.\n"; } else{ // validazione dei parametri tramite filtro per le stringhe $username = trim(filter_var($_POST['username'], FILTER_SANITIZE_STRING)); $password = trim(filter_var($_POST['password'], FILTER_SANITIZE_STRING)); $password = sha1($password); $data = new AdminSql(); $data->DbConnect($db_host,$db_user,$db_password,$db_name); // interrogazione della tabella $query = "SELECT id_login,group_login FROM login WHERE username_login = '$username' AND password_login = '$password'"; echo "$query \n"; echo $ref_page . "\n"; $auth = $data->DbQuery($query); if(mysqli_num_rows($auth)==0){ echo "login uncorrect\n"; //header("Location: " . $_SESSION['ref_page']); }else{ $res = $data->DbFetch($auth); $_SESSION['login'] = $res->id_login; echo $res->group_login; //$password = encGrp((string) $res->group_login); $password = crypt($res->group_login,base64_encode($res->group_login)); $_SESSION['group'] = $password; setcookie('intertino_id',md5(microtime().$_SERVER['REMOTE_ADDR']) .'_'.$password,time()+(86400*7)); $data->DbDisc(); header("Location: " . $ref_page); } } } } function LogOut(){ session_start(); $_SESSION = array(); session_destroy(); $msg = "LOG-OUT EFFETTUATO."; $msg = urlencode($msg); // non ci possono essere spazi nell'URL setcookie('intertino_id','',0); header("location: LogIn.php?msg=$msg"); exit(); }

LogIn/LogOut

php sql login form