index.html
Codice PHP:
<html>
<title>
</title>
<style type="text/css">
<!--
body {
background-color: #00FF66;
}
-->
</style><head>
<?php
"session_start();"
?>
<td align="center" valign="middle"><form action="controllo.php" method="post">
<table width="280" border="0" cellpadding="0" cellspacing="0">
<tr align="center" valign="middle">
<td width="140" height="30" align="center"><div align="center">[b]User : [/b]</div></td>
<td width="149" height="30"><input name="user" type="text" id="user" size="15"></td>
</tr>
<tr align="center" valign="middle">
<td height="30"><div align="center">[b]Password : [/b]</div></td>
<td height="30"><input name="password" type="password" id="password" size="15"></td>
</tr>
<tr align="center" valign="middle">
<td height="30"><input type="submit" name="Submit" value="Login"></td>
<td height="30" align="left"><input type="reset" name="Submit" value="Resetta"></td>
</tr>
</table>
</form>
</head>
</html>
intanto se includi uno script php l'estensione del file deve essere php,
seconda cosa
codice:
<?php "session_start();" ?>
va senza " " e prima di ogni output
sessione.php
Codice PHP:
<!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>
<?php
session_start();
if(!isset($_SESSION['user'])){
header("location:prova.html");
exit;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento senza titolo</title>
</head>
<body>
</body>
</html>
anche qui session_start() va prima di ogni output
prova.html
Codice PHP:
<!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>
<?php
include('sessione.php')
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento senza titolo</title>
<style type="text/css">
body {
background-color: #363;
text-align:center;
}
</style>
</head>
<body>
se includi uno script php l'estensione del file deve essere php