Salve a tutti ho iniziato da poco a studiare le sessioni ma non le riesco a far funzionare.
Ho scritto uno script che dopo il log-in mi fa visualizzare la lista di una tabella del database (la prima volta in ordine di chiave primaria).
Poi successivamente quando clicco su un link mi deve rioridnare la lista in base alla scelta dell'utente ma ogni volta devo ripetere il log-in mi sapresta aiutare???
Vi posto il codice della prima pagina :
Codice PHP:
<?php
session_start();
if(!isset($_SESSION['user']))
{
$_SESSION['user'] = 'a';
}
if(isset($_SESSION['bool']))
{
header('location:' . $_SERVER["PHP_SELF"] . '?' . SID);
};
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>
<h1>Log-In</h1>
<form action="Connessione_2.php?id=pk" method="post">
<input type="text" name="user" id="user" />
<input type="password" name="password" id="password" />
<button type="submit">Log in</button>
</form>
</body>
</html>
Vi posto il codice della seconda pagina :
Codice PHP:
<?php
session_start();
if(isset($_SESSION['user']))
{
$_SESSION['user'] = $_POST['user'];
$_SESSION['user'] = $_POST['password'];
}
if(isset($_SESSION['bool']))
{
header('location:' . $_SERVER["PHP_SELF"] . '?' . SID);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
<style type="text/css">
a:first-letter { color: #000000;}
</style>
</head>
<body>
<?php
$connessione = @mysql_connect("localhost", $_SESSION["user"], $_SESSION["password"]) or die ("<h1 style='color:#FF0000'>Connessione non riuscita: </h1>" . mysql_error());
echo "<h1 style='color: #00CC00;'>Connesso al Database Server</h1>\n";
// Stampare i valori di una tabella
$db = mysql_select_db(prodotti); // Scegli il Database
$query = " SELECT * FROM articoli ORDER BY " . $_GET['id'] . " ASC "; // Crea la query
$result = mysql_query($query); // Lancia la query
echo "<table border='1'>\n <tr>\n";
for ($i=0; $i < mysql_num_fields($result); $i++)
{
echo ' <th>[url="' . $_SERVER['PHP_SELF'] . '?id=' . mysql_field_name($result, $i) . '"]' . mysql_field_name($result, $i) . '[/url]</th>' ."\n";
}
echo " </tr>\n";
while ($row = mysql_fetch_row($result))
{
echo ' <tr>' . "\n" . ' <td>' . implode($row,"</td>\n <td>") . "</td>\n </tr>\n";
}
echo "</table>\n";
?>
</body>
</html>