sorry people I have just joined and havent had a chance to look through the site. Im doing the exercises in Wrox Beginning PHP5 SQL Apache wev development and am having problems setting and saving cookies. can anyone point me in the right direction or to some help files on the matter.
the question is:
- Write a program that formats a block of text (to be input by the user) based on preferences chosen
by the user. Give your user options for color of text, font choice, and size. Display the output
on a new page.
- In the program you created in step 4, allow your users the option of saving the information for
the next time they visit, and if they choose “yes,” save the information in a cookie.
this is what i have done and i am a bit lost as to what is happening:
file: changefont3.php
<?php
session_unset();
?>
<html>
<head>
<title>Change Font</title>
</head>
<body>
<form method="post" action="fonttext3.php">
<p>Enter your choice of font:
<select name="font">
<option value="Verdana">Verdana</option>
<option value="Ariel">Ariel</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Lucida Handwriting">Lucida Handwriting</option>
<option value="Century Gothic">Century Gothic</option>
<option value="Book Antiqua">Book Antiqua</option>
</select>
</p>
<p>Enter your choice of font size:
<select name="size">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</p>
<p>Enter your choice of font colour:
<select name="color">
<option value="black">Black</option>
<option value="blue">Blue</option>
<option value="orange">Orange</option>
<option value="purple">Purple</option>
<option value="green">Green</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
</select>
</p><br><hr>
<p>Please enter text to be formatted here:</p>
<p>
<textarea name="formtext" cols="50" rows="10"></textarea>
</p>
<p>Click here to save preferences for your next visit
<input name="pref" type="checkbox" value="y">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
and fonttext3.php
<?php
if ($POST['pref']=='y') {
setcookie('font',$POST['font'],time()+60602430);
setcookie('size',$POST['size'],time()+60602430);
setcookie('color',$POST['color'],time()+60602430);
setcookie('formtext',$_POST['formtext'],time()+60602430);
}
$COOKIE['font'] = $POST['font'];
$COOKIE['size'] = $POST['size'];
$COOKIE['color'] = $POST['color'];
$COOKIE['formtext'] = $POST['formtext'];
echo '<font face="';
echo $COOKIE['font'];
echo '" size="';
echo $COOKIE['size'];
echo '" color="';
echo $_COOKIE['color'];
echo '">';
echo '<p>';
echo $_COOKIE['formtext'];
echo '</p>';
echo '</font>';
?>
thanks for any guidance
Ozzie