Modulo di verifica rapida
Nella speranza di un sub libero ho deciso di postare un articolo di un codice PHP sulla validazione dell'input dell'utente, come ad iscriversi pagine. Così lascia iniziare. Prima di tutto controllare che la connessione:
php <? Php
con = mysql_connect ( " localhost " , " your_user " , " your_pass " ) ; $ Con = mysql_connect ("localhost", "your_user", "your_pass");
$ con ) if (! $ con)
{
" < h2 > Sorry , we can not process your request at this time , please try again later < / h2 > < br / > n " ; echo "<h2> Spiacenti, non possiamo elaborare la tua richiesta in questo momento, riprova più tardi </ h2> <br /> n";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
uscita;
}
Se questo non è vero che li reindirizza con un paio di collegamenti ipertestuali. Se fosse vero continuiamo e impostare alcune variabili.
" grandma_recipe " , $ con ) or die ( ' Could not connect to database ' ) ; mysql_select_db ("grandma_recipe", $ con) or die ('Impossibile connettersi al database');
userid = $ _POST [ ' userid ' ] ; $ Userid = $ _POST ['userid'];
password = $ _POST [ ' password ' ] ; $ Password = $ _POST ['password'];
password2 = $ _POST [ ' password2 ' ] ; Password2 $ = $ _POST ['password2'];
fullname = $ _POST [ ' fullname ' ] ; Fullname $ = $ _POST ['fullname'];
email = $ _POST [ ' email ' ] ; $ Email = $ _POST ['email'];
baduser = 0 ; $ Baduser = 0;
p > Everything is grabbed via $ _post method from user input . Next we will check it < / p > <P> Tutto è afferrato tramite il metodo $ _POST dall'input dell'utente. Successiva si provvederà a controllare it </ p>
code > <Code>
Check if userid was entered / / Verifica se è stato inserito userid
trim ( $ userid ) = = ' ' ) if (trim ($ userid) == '')
{
" < h2 > Sorry , you must enter a user name . < / h2 > < br > n " ; echo "<h2> Mi dispiace, è necessario immettere un nome utente </ h2> <br> n.";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
baduser = 1 ; Baduser = $ 1;
}
Check if password was entered / / Verifica se la password è stata inserita
trim ( $ password ) = = ' ' ) if (trim ($ password) == '')
{
" < h2 > Sorry , you must enter a password . < / h2 > < br / > n " ; echo "<h2> Mi dispiace, è necessario immettere una password </ h2> <br /> n.";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
baduser = 1 ; Baduser = $ 1;
}
Check if password and confirm password match / / Verifica se la password e confermare la password partita
$ password ! = $ password2 ) if ($ password! = $ password2)
{
" < h2 > Sorry , the passwords you entered did not match . < / h2 > < br > n " ; echo "<h2> Mi dispiace, le password che hai inserito non corrispondono </ h2> <br> n.";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
baduser = 1 ; Baduser = $ 1;
}
Check if userid is already in database / / Verifica se userid è già presente nel database
query = " SELECT userid from users where userid = ' $ userid ' " ; $ Query = "userid SELECT da utenti dove userid = '$ userid'";
result = mysql_query ( $ query ) ; $ Risultato = mysql_query ($ query);
row = mysql_fetch_array ( $ result , MYSQL_ASSOC ) ; $ Row = mysql_fetch_array ($ risultato, MYSQL_ASSOC);
$ row [ ' userid ' ] = = $ userid ) if ($ row ['userid'] == $ userid)
{
" < h2 > Sorry , that user name is already taken . < / h2 > < br > n " ; echo "<h2> Mi dispiace, che il nome utente è già </ h2> <br> n.";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
baduser = 1 ; Baduser = $ 1;
}
check for correct email parameters / / Controlla i parametri corretti e-mail
{
" < h2 > That is not a valid email ! < / h2 > < / br > n " ; echo "<h2> Questo non è un indirizzo email valido </ h2> </ br> n!";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
baduser = 1 ; Baduser = $ 1;
}
Ora che i dati ha superato le nostre prove possiamo entrare nel nostro db, anche avviare la sessione dell'utente.
$ baduser ! = 1 ) if ($ baduser! = 1)
{
Everything passed , enter userid in database / / Tutto passa, inserire userid nel database
query = " INSERT into users VALUES ( ' $ userid ' , PASSWORD ( ' $ password ' ) , ' $ fullname ' , ' $ email ' ) " ; $ Query = "INSERT INTO utenti ('$ userid', PASSWORD ('$ password'), '$ fullname', '$ email')";
result = mysql_query ( $ query ) or die ( ' Sorry , we are unable to process your request . ' ) ; $ Risultato = mysql_query ($ query) or die ('Mi dispiace, siamo in grado di elaborare la tua richiesta.');
$ result ) if ($ result)
{
_SESSION [ ' valid_recipe_user ' ] = $ userid ; $ _SESSION ['Valid_recipe_user'] = $ userid;
" < h2 > Your registration request has been approved and you are now logged in ! < / h2 > n " ; echo "<h2> La tua richiesta di registrazione è stata approvata e si è effettuato l'accesso </ h2> n!";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
uscita;
}
altro
{
" < h2 > Sorry , there was a problem processing your login request < / h2 > < br > n " ; echo "<h2> Spiacente, c'è stato un problema l'elaborazione della richiesta di accesso </ h2> <br> n";
" < a href = " index . php ? content = register " > Try again < / a > < br > n " ; echo "<a href =" index php content = registrazione.? "> Prova di nuovo </ a> <br> n";
" < a href = " index . php " > Return to Home < / a > n " ; echo "<a href =" index php. "> Return to Home </ a> n";
}
}
Molti metodi più possono essere utilizzati per convalidare l'input dell'utente, che è molto importante. Questa dovrebbe essere una guida per iniziare a costruire per una maggiore sicurezza.
Nessun commento è stato fornito.
Scritto da Jonathan Teel
Ultimo aggiornamento: 2011/10/25 16:00:38