ciao, sto seguendo alcuni es. da libro per impostare un cookie.
in un form vien data la possibilità di settare appunto un cookie per far si che ricordi alcune impostazioni, poi un if nel caso sia flaggata questa checkbox crea appunto il cookie e poi mi perdo.
pagina della form:
Codice PHP:
<?php
session_unset();
?>
<!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>Please log in</title>
</head>
<body>
<?php include "header.php"; ?>
<form method="post" action="movie1.php">
Enter your font choice:
<select name="font">
<option value="Verdana">Verdana</option>
<option value="Arial">Arial</option>
<option value="Geneva">Geneva</option>
</select>
</p>
Enter your font size:
<select name="size">
<option value="1em">1 em</option>
<option value="2em">2 em</option>
<option value="3em">3 em</option>
</select>
</p>
Enter your color:
<select name="color">
<option value="#000">black</option>
<option value="#f00">red</option>
<option value="#00f">blue</option>
</select>
</p>
Enter your text:
<textarea name="testo" cols="25" rows="8"></textarea>
Enter your username:
<input type="text" name="user" />
</p>
Enter your password:
<input type="password" name="pass" />
</p>
Do you want to save these preferences for the next time you log in?
<input type="checkbox" name="pref" value="y" />
</p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
pagina che elabora la form:
Codice PHP:
<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;
if ($_POST['pref']=='y') {
setcookie('font', $_POST['font'], time()+60);
setcookie('size', $_POST['size'], time()+60);
setcookie('color', $_POST['color'], time()+60);
}
// Verifica le info relative a nome utente e pwd
if (($_SESSION['username'] == 'Joe') and
($_SESSION['userpass'] == '12345')) {
$_SESSION['authuser'] = 1;
} else {
echo "Sorry, but you don't have permission to view this page, you loser!";
exit();
}
?>
<!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>Find My Favorite Movie!</title>
<style type="text/css">
h6 {
font-family: <?php echo $_POST['font'] ?>;
font-size: <?php echo $_POST['size'] ?>;
color: <?php echo $_POST['color'] ?>;
}
</style>
</head>
<body>
<?php include "header.php"; ?>
<?php
$myfavmovie = urlencode("Life of Brian");
echo "<a href='moviesite.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "</a>";
echo "
";
echo "Or choose how many movies you would like to see: ";
?>
<form method="post" action="moviesite.php">
Enter number of movies (up to 10):
<input type="text" name="num" />
Check here if you want the list sorted alphabetically:
<input type="checkbox" name="sorted" />
</p>
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
echo "<h6>" . $_POST['testo'] . "</h6>";
?>
<?php
include "mail.php";
?>
</body>
</html>
non giurerei di aver messo l'if dove va, poi l'es. del libro mi dice che invece di accedere alle variabili tramite sessioni posso farlo tramite cookie così:
Codice PHP:
echo $_COOKIE['font'];
ma nn capisco bene la cosa, dove metterlo, perchè c'è solo font (size e color?)
insomma sono un pò confuso...
grazie