Ecco il codice!
questo è il file config.php
<?php
$mysql['host'] = "";
$mysql['pass'] = "";
$mysql['user'] = "";
$mysql['name'] = "";
@mysql_connect($mysql['mysql.netsons.com'], $mysql['user'], $mysql['pass']);
@mysql_select_db($mysql['vitesilv_db']);
?>
poi install.php
<?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();
?>
Questa è la pagina per la registrazione: join.php
<?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();
?>
e la pagina del profilo: user.php
<?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();
?>
poi il modulo del login: login.php
<?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 "<select name=\"user\">\n";
echo "<option>Seleziona...</option>\n";
echo $user;
echo "</select>\n";
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();
la lista degli utenti iscritti: memberslist.php
<?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();
?>
ed il controllo: check.php
<?php
if (!isset($_COOKIE["logged"]))
{
echo "Non sei ancora loggato!<br>\n";
require("login.php");
exit();
}
?>
in fine la pagina dell'area riservata: index.php
<?php
require("config.php");
require("check.php");
?>
<html>
<body>
...
Il resto della pagina...
...
</body>
</html>
E questo è tutto.... come ripeto, dopo aver effettuato la registrazione l'utente non compare nella memberslist e con le sue credenziali non riesce ad accedere alla pagina privata... Potrebbe essere una questione di permessi di scrittura???