Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    script che non funziona con register_globals a off

    Ciao a tutti,
    ho un problema relativo a dei files (3) che mi permettono di inserire gli utenti e dare loro dei permessi per poi accedere all'area riservata per la gestione del sito.

    Il primo file è la form che mi permette di inserire Cognome, Nome, User, Password e il tipo di utente, nel mio caso possono essere due (admin e redattore).
    Admin può fare tutto, mentre a chi redattore vengono dati i permessi.
    E proprio qua c'è il problema.
    Omettendo i primo file di cui sopra invio il secondo:

    utenti_ins2.php
    Codice PHP:
    <?php 
    $cognome 
    ucwords($_POST['cognome']);           
    $cognome ucwords(strtolower($cognome)); 
    $nome ucwords($_POST['nome']);           
    $nome ucwords(strtolower($nome)); 
    $username ucwords($_POST['username']);           
    $username ucwords(strtolower($username)); 
    $password $_POST['password'];           
    //controllo se l'utente è già stato inserito
    $utente $_POST['username'];//utente preso dalla form
    $sql mysql_query("select * from utenti where username = '$utente'");
    //prelevo dal database tutti gli utenti che hanno il codice inserito nella form
    $row mysql_fetch_array($sql);
    $cerca mysql_num_rows($sql); //conto gli utenti
    if($cerca 0) { //se l'utente è presente 
    ?>
    [img]img/attenzione.png[/img]
    <?php print" [b]ATTENZIONE[/b]"."

    "
    ."la login"."

    "
    ." [b] $utente [/b]" ."

    "
    "è già stata assegnata all'utente""

    "
    "[b]$row[cognome]$row[nome][/b] " ?>
        <form name="form1" method="post" action="utenti_ins.php">
            <input type="hidden" name="cognome" value="<?php print "$cognome"?>">
            <input type="hidden" name="nome" value="<?php print "$nome"?>">
            <input type="hidden" name="username" value="<?php print "$username"?>">
            <input type="hidden" name="password" value="<?php print "$password"?>">
            <input type="submit" name="Submit" value="Torna Indietro">        
          </form>
    <?php
    exit; 
    }    
    //fine controllo
    ?>
    <?php
    if ($_POST['tipo'] == "admin") {
    $query mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')"); 
    //header("Location: utenti_lista.php");
    exit;
    } else {
    ?>
    <?php
    include("top_foot.inc.php"); 
    ?>    
          <?php if (checkpermessi("inserimento","utenti",$_SESSION['login_staff_utente'])) { ?>
              <form action="utenti_ins3.php" method="post" name="form">
    Inserimento Nuovo Utente 2/2 User:  
                                <input name="username" type="hidden" id="username" value="<?php print "$username"?>">
                                <?php print stripslashes("$username"); ?>[/b]</td>
                            Cognome: 
                                <input name="cognome" type="hidden" id="cognome" value="<?php print "$cognome"?>">
                                <?php print "$cognome"?> Nome:
                                <input name="nome" type="hidden" id="nome" value="<?php print "$nome"?>">
                                <?php print "$nome"?> Tipo 
                                <input name="tipo" type="hidden" id="tipo" value="<?php print $_POST['tipo']; ?>">
                                <?php print $_POST['tipo']; ?> 
                             <input name="password" type="hidden" id="password" value="<?php print "$password"?>">
                            
                  <?php  if ($_POST['tipo'] != "admin") { ?>
                  Inserimento Permessi Utente              
                  <?php $aree = array("news","articoli","convegni","incontri_ed_eventi"); ?>
                  Aree di gestione[/B]
                      
                    <?php foreach ($aree as $area) { ?>
                      <td width="150" align="left" bgcolor="D3D8E2">[b]<?php print strtr(ucfirst($area),"_"," "); ?>[/b]</td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_inserisci " " type=checkbox id=".$area."_inserisci " "value='ok'>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_modifica " " type=checkbox id=".$area."_modifica " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_elimina " " type=checkbox id=".$area."_elimina " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_allega " " type=checkbox id=".$area."_allega " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_eliminaall " " type=checkbox id=".$area."_eliminaall " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_visualizza " " type=checkbox checked=checked id=".$area."_visualizza " "value=ok>"?>
                    <?php ?>
                  <?php ?>
                  <input name="submit" type=submit value="continua">
                              </form>
                
    <?php } else {
        
    header("Location: index.php");
        exit;
    }
    ?>
                        <?php /* footer */
                        
    foot();
                        
    ?>
    <?php 
    }} ?>
    Dal quale dopo aver dato i vari permessi invia tutto al terzo file per la registrazione dell'utente:

    utenti_ins3.php
    Codice PHP:
    <?php
    $cognome 
    $_POST['cognome'];
    $nome $_POST['nome'];
    $username $_POST['username'];
    $password $_POST['password'];
    ////
    $query mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')"); 
    ////    
        
    $query mysql_query("SELECT idutente FROM utenti WHERE username = '".$username."'");
        
    $row mysql_fetch_array($query);
        
    $id $row['idutente'];
        
    // inserisci permessi
        
    $aree $aree = array("news","articoli","convegni","incontri_ed_eventi");
        foreach (
    $aree as $area) {
    $ck_ins "$area"."_inserisci";
    $ck_mod "$area"."_modifica";
    $ck_can "$area"."_elimina";
    $ck_all "$area"."_allega";
    $ck_eliall "$area"."_eliminaall";
    $ck_vis "$area"."_visualizza";
            if ($
    $ck_all == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','ins_allegati')"); }        
            if ($
    $ck_eliall == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','canc_allegati')"); }
            if ($
    $ck_ins == "ok") {mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES ("$id ",'".$area."','inserimento')");} 
            if ($
    $ck_mod == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','modifica')"); }
            if ($
    $ck_can == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','elimina')"); }
            if ($
    $ck_vis == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','visualizza')"); }
       }

      
    header("Location: utenti_lista.php");
    exit;
    }
    ?>
    In effetti funziona tutto alla perfezione, a patto che il register_globals è settato ad ON, ma se lo imposto ad OFF così come deve essere, non mi registra i permessi.
    Aspetto vostro aiuto.

  2. #2
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    a parte che io pulirei un po' il codice...

    comunque non recuperi i POST delle aree

    Codice PHP:
    <?php 
    $cognome 
    ucwords(strtolower($_POST['cognome']));
    $nome ucwords(strtolower($_POST['nome']));
    $username ucwords(strtolower($_POST['username']));
    $password $_POST['password'];

    //controllo se l'utente è già stato inserito
    $sql mysql_query("select * from utenti where username = '$username'");

    //prelevo dal database tutti gli utenti che hanno il codice inserito nella form
    $row mysql_fetch_array($sql);
    $cerca mysql_num_rows($sql);

    if(
    $cerca 0) { //se l'utente è presente 
    ?>
    [img]img/attenzione.png[/img]
    <?php print" [b]ATTENZIONE[/b]"."

    "
    ."la login"."

    "
    ." [b] $utente [/b]" ."

    "
    "è già stata assegnata all'utente""

    "
    "[b]$row[cognome]$row[nome][/b] " ?>
        <form name="form1" method="post" action="utenti_ins.php">
            <input type="hidden" name="cognome" value="<?php print "$cognome"?>">
            <input type="hidden" name="nome" value="<?php print "$nome"?>">
            <input type="hidden" name="username" value="<?php print "$username"?>">
            <input type="hidden" name="password" value="<?php print "$password"?>">
            <input type="submit" name="Submit" value="Torna Indietro">
          </form>
    <?php
    exit;
    }
    //fine controllo

    if ($_POST['tipo'] == "admin") {
    $query mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')"); 
    //header("Location: utenti_lista.php");
    exit;
    } else {

    include(
    "top_foot.inc.php"); 

    if (
    checkpermessi("inserimento","utenti",$_SESSION['login_staff_utente'])) { ?>
              <form action="utenti_ins3.php" method="post" name="form">
    Inserimento Nuovo Utente 2/2 User:  
                                <input name="username" type="hidden" id="username" value="<?php print "$username"?>">
                                <?php print stripslashes("$username"); ?>[/b]</td>
                            Cognome: 
                                <input name="cognome" type="hidden" id="cognome" value="<?php print "$cognome"?>">
                                <?php print "$cognome"?> Nome:
                                <input name="nome" type="hidden" id="nome" value="<?php print "$nome"?>">
                                <?php print "$nome"?> Tipo 
                                <input name="tipo" type="hidden" id="tipo" value="<?php print $_POST['tipo']; ?>">// attento che l'utente non modifichi questo valore!!
                                <?php print $_POST['tipo']; ?> 
                             <input name="password" type="hidden" id="password" value="<?php print "$password"?>">
                            
                  <?php  if ($_POST['tipo'] != "admin") { ?>
                  Inserimento Permessi Utente              
                  <?php $aree = array("news","articoli","convegni","incontri_ed_eventi"); ?>
                  Aree di gestione[/B]
                      
                    <?php foreach ($aree as $area) { ?>
                      <td width="150" align="left" bgcolor="D3D8E2">[b]<?php print strtr(ucfirst($area),"_"," "); ?>[/b]</td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_inserisci " " type=checkbox id=".$area."_inserisci " "value='ok'>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_modifica " " type=checkbox id=".$area."_modifica " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_elimina " " type=checkbox id=".$area."_elimina " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_allega " " type=checkbox id=".$area."_allega " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_eliminaall " " type=checkbox id=".$area."_eliminaall " "value=ok>"?></td>
                      <td width="70" align="center" bgcolor="D3D8E2"><?php print "<input name=".$area."_visualizza " " type=checkbox checked=checked id=".$area."_visualizza " "value=ok>"?>
                    <?php ?>
                  <?php ?>
                  <input name="submit" type=submit value="continua">
                              </form>
                
    <?php } else {
        
    header("Location: index.php");
        exit;
    }
    /* footer */
                        
    foot();
    }



    ?>
    Codice PHP:
    <?php
    $cognome 
    $_POST['cognome'];
    $nome $_POST['nome'];
    $username $_POST['username'];
    $password $_POST['password'];
    ////
    $query mysql_query("INSERT INTO utenti (cognome,nome,username,password,tipo) VALUES ('$cognome','$nome','$username','$password','$tipo')"); 
    ////    
        
    $query mysql_query("SELECT idutente FROM utenti WHERE username = '".$username."'");
        
    $row mysql_fetch_array($query);
        
    $id $row['idutente'];
        
    // inserisci permessi
        
    $aree $aree = array("news","articoli","convegni","incontri_ed_eventi");
        foreach (
    $aree as $area) {
    $ck_ins "$area"."_inserisci";
    $ck_mod "$area"."_modifica";
    $ck_can "$area"."_elimina";
    $ck_all "$area"."_allega";
    $ck_eliall "$area"."_eliminaall";
    $ck_vis "$area"."_visualizza";

            if (
    $_POST[$ck_all] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','ins_allegati')"); }        
            if (
    $_POST[$ck_eliall] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','canc_allegati')"); }
            if (
    $_POST[$ck_ins] == "ok") {mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES ("$id ",'".$area."','inserimento')");} 
            if (
    $_POST[$ck_mod] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','modifica')"); }
            if (
    $_POST[$ck_can] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','elimina')"); }
            if (
    $_POST[$ck_vis] == "ok") { mysql_query("INSERT INTO permessi (idutente,sezione,azione) VALUES (".$id.",'".$area."','visualizza')"); }
       }

      
    header("Location: utenti_lista.php");
    exit;
    }
    ?>

  3. #3
    ok funziona.
    Grazie
    Mi dai qualche dritta su come ripulire il codice?

  4. #4
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    per esempio all'inizio scrivi
    Codice PHP:
    $cognome ucwords($_POST['cognome']);
    $cognome ucwords(strtolower($cognome)); 
    quando basta un
    Codice PHP:
    $cognome ucwords(strtolower($_POST['cognome'])); 
    poi dividerei la parte php da quella html

  5. #5
    Grazie per le dritte.
    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.