Salve a tutti, ho deciso di mettere il login nella mia pagina web..
Ho creato sette pagine in PHP, leggendo in un sito come fare...
So già che nessuno risponderà><
check.php
config.phpCodice:<html> <head> </head> <body> <?php if (!isset($_COOKIE["logged"])) { echo "Non sei ancora loggato!<br>\n"; require("login.php"); exit(); } ?> </body> </html>
Li ho compilati, i campi pass host etc...Codice:<?php $mysql['host'] = ""; $mysql['pass'] = ""; $mysql['user'] = ""; $mysql['name'] = ""; @mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']); @mysql_select_db($mysql['name']); ?>
install.php
Ho creato la tabella.Codice:<html> <head> </head> <body><?php require("config.php"); echo "<h1>Installazione</h1>\n"; echo "Ok!<br>\n"; echo "Installazione avvenuta con successo.\n"; @mysql_query("CREATE TABLE 'members' ( 'id' INT( 11 ) NOT NULL AUTO_INCREMENT , 'user' VARCHAR( 255 ) NOT NULL , 'pass' VARCHAR( 255 ) NOT NULL , 'nome' VARCHAR( 255 ) NOT NULL , 'cognome' VARCHAR( 255 ) NOT NULL , 'age' VARCHAR( 255 ) NOT NULL , 'city' VARCHAR( 255 ) NOT NULL , 'hobby' TEXT NOT NULL , INDEX ( 'id' ) ); "); @mysql_close(); ?> </body> </html>
join.php
<html>
<head>
</head>
<body><?php
require("config.php");
echo "<h1>Registrazione</h1>\n";
if ($action == FALSE)
{
echo "<form action=\"./join.php\" method=\"post\">\n";
echo "<table width=\"100%\" border=\"0\">\n";
echo "<tr>\n";
echo "<td width=\"9%\"><strong>Username *</strong></td>\n";
echo "<td width=\"91%\"><input name=\"user\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><strong>Password *</strong></td>\n";
echo "<td><input name=\"pass\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><strong>Nome *</strong></td>\n";
echo "<td><input name=\"nome\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><strong>Cognome</strong></td>\n";
echo "<td><input name=\"cognome\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><strong>Età *</strong></td>\n";
echo "<td><input name=\"age\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><strong>Città</strong></td>\n";
echo "<td><input name=\"city\" type=\"text\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td valign=\"top\"><strong>Hobby *</strong></td>\n";
echo "<td><textarea name=\"hobby\"></textarea></td>\n";
echo "</tr>\n";
echo "<tr align=\"center\">\n";
echo "<td colspan=\"2\"><input type=\"hidden\" name=\"action\" value=\"join\"><input type=\"submit\" value=\" Join! \"></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
else
{
if ($user==TRUE && $pass==TRUE && $nome==TRUE && $age==TRUE && $hobby==TRUE)
{
if ($cognome == FALSE) $cognome = "n/a";
if ($city == FALSE) $city = "n/a";
@mysql_query("INSERT INTO 'members' ( 'id' , 'user' , 'pass' , 'nome' , 'cognome' , 'age' , 'city' , 'hobby' )
VALUES ('',
'" . $user . "',
'" . $pass . "',
'" . $nome . "',
'" . $cognome . "',
'" . $age . "',
'" . $city . "',
'" . $hobby . "');");
echo "Grazie!<br>Registrazione effettuata correttamente!"
}
else
{
echo "Errore!<br>Non hai compilato tutti i campi obbligatori.";
}
}
@mysql_close();
?>
</body>
</html>
login.php
memberslist.phpCodice:<html> <head> </head> <body> <?php require("config.php"); echo "<h1>Login</h1>\n"; // Parte A if ($action == FALSE) { $user = ""; $query = @mysql_query("SELECT * FROM members ORDER BY nome ASC"); while($result = @mysql_fetch_array($query)) { $user .= "<option value=\"" . $result[0] . "\">" . $result[1] . "</option>\n"; } echo "<form action=\"./login.php\" method=\"post\">\n"; echo "<table width=\"100%\" border=\"0\">\n"; echo "<tr>\n"; echo "<td width=\"8%\"><strong>Username</strong></td>\n"; echo "<td width=\"92%\">\n"; echo "<input type=\"user\" name=\"user\"><\td> \n"; echo $user; echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td><strong>Password</strong></td>\n"; echo "<td><input type=\"password\" name=\"pass\"></td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td colspan=\"2\">\n"; echo "<input type=\"hidden\" name=\"action\" value=\"login\">\n"; echo "<input type=\"submit\" value=\" Login! \">\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "</form>\n"; } // Parte B else { if ($user == TRUE && $pass == TRUE) { $query = @mysql_query("SELECT * FROM members WHERE id = $user"); $result = @mysql_fetch_array($query); if ($pass == $result[2]) { @setcookie("logged"); echo "Ok!<br>\n"; echo "Login effettuato correttamente!"; echo "<a href=\"./privata.php\">Entra nella sezione privata!</a>"; } else { echo "Errore!<br>Password errata!"; } } else { echo "Errore!<br>Non hai compilato tutti i campi obbligatori."; } } @mysql_close(); ?> </body> </html>
Codice:<html> <head> </head> <body><?php require("config.php"); $memberslist = ""; $query = @mysql_query("SELECT * FROM members ORDER BY nome ASC"); while($result = @mysql_fetch_array($query)) { $memberslist .= "<tr>"; $memberslist .= "<td><a href=\"./user.php?id=" . $result[0] . "\">" . $result[3] . "</a></td>\n"; $memberslist .= "</tr>\n"; } echo "<h1>Lista</h1>\n"; echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\">\n"; echo "<tr>"; echo "<td><strong>Nome/nick</strong></td>\n"; echo "</tr>\n"; echo $memberslist; echo "</table>\n"; @mysql_close(); ?> </body> </html>
user.php
Ecco, questi sono i file...Codice:<html> <head> </head> <body> <?php require("config.php"); $query = @mysql_query("SELECT * FROM members WHERE id = $id"); $result = @mysql_fetch_array($query); echo "<h1>Profilo</h1>\n"; echo "<table width=\"100%\" border=\"0\">\n"; echo "<tr>\n"; echo "<td width=\"10%\"><strong>Nome</strong></td>\n"; echo "<td width=\"90%\">" . $result[3] . "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td><strong>Cognome</strong></td>\n"; echo "<td>" . $result[4] . "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td><strong>Età</strong></td>\n"; echo "<td>" . $result[5] . "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td><strong>Città</strong></td>\n"; echo "<td>" . $result[6] . "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td valign=\"top\"><strong>Hobby</strong></td>\n"; echo "<td>" . str_replace("\n", "<br>", $result[7]) . "</td>\n"; echo "</tr>\n"; echo "</table>\n"; @mysql_close(); ?> </body> </html>
Ora, quando arrivo a registrarmi, mi dice che ho fatto, ma non mi fa eseguire il login ne mi conta nella lista membri, in poche parole non registra.
potete vederlo da:
Registra!!! [URL="http://makkas.altervista.org/Login/login.php"]Login!!!URL]

LinkBack URL
About LinkBacks



