Ciao a tutti:
questo è il form per il log in:
Codice PHP:
<form method="post" action="verifica_log.php">
<table width="100%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="27%">[b]Squadra:[/b]</td>
<td width="73%">
<input name="team" type="text" maxlength="255">
</td>
</tr>
<tr>
<td width="23%">[b]Password:[/b]</td>
<td width="77%">
<input name="pass" type="password" maxlength="255">
</td>
</tr>
<tr>
<td><input type="submit" name="connessione" value="Collegati" class="Button"/></td>
</tr>
</table>
</form>
verifica_log.php
Codice PHP:
<?php
session_start();
//connessione al database
include('connect.php');
if($_POST) {
effettua_login();
}
else
{
mostra_form();
}
function effettua_login()
{
// recupero il nome e la password inseriti dall'utente
$team= trim(filter_var($_POST['team'], FILTER_SANITIZE_STRING));
$pass= trim(filter_var($_POST['pass'], FILTER_SANITIZE_STRING));
$pass= sha1($pass);
// verifico se devo eliminare gli slash inseriti automaticamente da PHP
if(get_magic_quotes_gpc()) {
$team = stripslashes($team);
$pass = stripslashes($pass);
}
// verifico la presenza dei campi obbligatori
if(!$team || !$pass) {
header("location:log_error.php");
exit;
}
// effettuo l'escape dei caratteri speciali per inserirli all'interno della query
$team = mysql_real_escape_string($team);
$pass = mysql_real_escape_string($pass);
// preparo ed invio la query
$query = "SELECT * FROM iscritti WHERE team='$team' AND password='$pass'";
$result = mysql_query($query);
// controllo l'esito
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
$record = mysql_fetch_array($result);
if(!$record) {
header("location:log_error.php");
} else {
session_start();
$_SESSION['username'] = $_POST['team'];
header("location:log_success.php");
}
}
?>
sessione.php(questa pagina l'ho inclusa in tutte quelle dove per entrare è necessario fare il log in:
Codice PHP:
<?php
session_start();
if(!isset($_SESSION['username'])){
header("location:../log_error.php");
exit;
}
?>
la pagina game_index.php
Codice PHP:
<?php
$team = $_POST['team'];
var_dump($team);
$query="SELECT * FROM SQUADRA_dati WHERE team='$team'";
var_dump($query);
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr>";
echo "<td>". $row['team']. "</td><td>". $row['manager']. "</td><td>". $row['punti']."</td><td>". $row['vittorie']. "</td><td>". $row['pareggi']. "</td><td>". $row['sconfitte']. "</td>";
echo "</tr>";
}
echo "</table>";
?>
Io vorrei mostrare all'utente i suoi dati,ma questo non avviene perchè i var_dump mi restituiscono NULL come risultato.
Potete aiutarmi?