Problema Community

  • Creatore Discussione Creatore Discussione MakkaS
  • Data di inizio Data di inizio

MakkaS

Nuovo Utente
18 Nov 2008
8
0
0
Salve, ho letto il tutorial per creare una piccola community nel mio sito...
Molto carino devo dire...
Ma avrei delle domande da fare:
-Mi potete dire come fare per togliere il menu a tendina, quello che fa selezionare gli utenti per accedere, e mettere un normale textarea?!?
-C'è un modo per cancellare gli utenti?!?Se si, quale?!?
-Non ottengo il risultato che voelvo.. inserendo il codice che dice il tutorial, le pagine restano normali e visitabili... suggeritewmi una soluzione...

Se vi interessa uso altervista e ho messo tutti i file nella cartella /Login.
Grazie in anticipo, MakkaS
 
Quanta fretta :), postami il link al tutorial che vediamo cosa si può fare.
 
Allora, ho dato un'occhiata veloce al tutorial che hai linkato e per quento riguarda l'eliminazione della tendina di selezione utenti la cosa è fattibile ma comporta un po' di modifiche non solo al codice, ma anche alla struttura del DB. Da quello che vedo il menu a tendina viene creato selezionando dal DB l'id e la username dei vari utenti iscritti. Purtroppo in fase di registrazione non vengono fatti controlli sull'univocità della username in quanto ciò che distingue i vari utenti è l'id. Per questo motivo se vuoi eliminare il menu a tendina e sostituirlo con campo di testo dovrai inserire in esso l'id dell'utente e non la username in fase di accesso.
Per quanto riguarda il problema che le pagine restano visitabili probabilmente ciò e dovuto al fatto che il cookie di avvenuto login viene creato in fase di accesso, ma mai rimosso per cui il controllo funziona quanto il cookie è assente, ma dopo il primo accesso il controllo lo troverà sempre e permetterà l'accesso alle pagine. Puoi provare ad eliminare i cookie da browser e vedere se così funziona. in caso affermativo devi preoccuparti, dopo la procedura di accesso alle pagine protette, di implementare anche uno script per l'uscita e la rimozione del cookie.
 
Non ho capito bene la prima parte, ho comunque risolto tutto, tranne appunto il fatto della selezione.
Se c'è una soluzione, anche modificando la tabella o altro, mi piacerebbe saperla, modificherò.
 
Probabilmente più che una textarea ti coverrebbe utilizzare un semplice campo di testo in cui inserire la username dell'utente che si vuole loggare.
Quindi la prima cosa da fare è quella di eliminare tutta la parte delle query di estrazione degli users:
PHP:
# codice da rimuovere
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";

che andrai a sostituire con:
PHP:
echo "<td><strong>Username</strong></td>\n";
echo "<td><input type=\"text\" name=\"user\"></td>\n";

a questo punto non potrai più effettuare la query di login con l'id, dovrai invece utilizzare la username, quindi devi fare in modo che due utenti non possano averla uguale.
 
Non funge, grazie per aver rispoosto.
Dice che la pass è sbagliata.
Comunque avevo fatto delle modifiche, ti faccio vedere come sono ora i file.

check.php
PHP:
<?php
if (!isset($_COOKIE["logged"]))
{
echo "Non sei ancora loggato!<br>\n";
require("login.php");
exit();
}
?>

config.php
PHP:
<?php
$mysql['host'] = "localhost";
$mysql['pass'] = "";
$mysql['user'] = "makkas";
$mysql['name'] = "my_makkas";

@mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
@mysql_select_db($mysql['name']);
?>

install.php
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 PRIMARY KEY ,
`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 
) ENGINE = MYISAM ;
");

@mysql_close();
?>

join.php
PHP:
<?php
echo "<center>";
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 "<center>";
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 (NULL,
'" . $user . "',
'" . $pass . "',
'" . $nome . "',
'" . $cognome . "',
'" . $age . "',
'" . $city . "',
'" . $hobby . "');");

echo "Grazie!<br>Registrazione effettuata correttamente!";
echo "<a href=\"login.php\">Effettua da qui il login!";
}
else
{
echo "Errore!<br>Non hai compilato tutti i campi obbligatori.";
echo "<a href=\"join.php\">Riprova a registrarti!</a>";
}
}

@mysql_close();
?>
<center>

login.php
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><strong>Username</strong></td>\n";
echo "<td><input type=\"text\" name=\"user\"></td>\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();
?>

memberslist.php
PHP:
<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
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();
?>

Grazie in anticipo. MakkaS
 
sotituisci con:
PHP:
$query = mysql_query("SELECT * FROM members WHERE id = $user") or die (mysql_error()) ; 
$result = mysql_fetch_array($query);

e vedi se ti restituisce qualche errore-
 
Attuale login.php
PHP:
<?php
require("config.php");

echo "<h1>Login</h1>\n";

// Parte A
if ($action == FALSE)
{
$user = "";
$query = mysql_query("SELECT * FROM members WHERE id = $user") or die (mysql_error()) ;  
$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><strong>Username</strong></td>\n";
echo "<td><input type=\"text\" name=\"user\"></td>\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();
?>

E mostra come errore:
PHP:
Parse error: syntax error, unexpected '}' in /membri/makkas/Sito/login.php on line 31

Se tolgo la graffa viene unexpected T_ELSE
 

Discussioni simili