MoMoMajor Posted October 16, 2008 Share Posted October 16, 2008 Hi. I am reading about cookies in php and came across some code I am difficulty understanding. Here is the code in it's entirety: <?php //cookies.php if ($_POST[type_sel]) { setcookie("font[type]", $_POST[type_sel], time()+3600); } if ($_POST[size_sel]) { setcookie("font[size]", $_POST[size_sel], time()+3600); } $type = array("arial", "helvetica", "sans-serif", "courier"); $size = array("1","2","3","4","5","6","7"); echo "<html><head><title>Cookie Test</title></head><body><div align='center'>"; //The following form contains a pair of list boxes, which can be used to specify the //user's preferences: echo "<form method='POST'>"; echo "What font type would you like to use? "; echo "<select name='type_sel'>"; echo "<option selected value=''>default</option>"; foreach ($type as $var) { echo "<option>$var</option>"; } echo "</select><br><br>"; echo "What font size would you like to use? "; echo "<select name='size_sel'>"; echo "<option selected value=''>default</option>"; foreach ($size as $var) { echo "<option>$var</option>"; } echo "</select><br><br>"; echo "<input type='submit'>"; echo "</form>";[/i] echo "<b>Your cookies say:</b><br>"; echo "<font "; [b]if ($_COOKIE[font][type]) {[/b] [b] $cookie_font_type = $_COOKIE[font][type];[/b] echo "face='$cookie_font_type' "; } [b]if ($_COOKIE[font][size]) { $cookie_font_size = $_COOKIE[font][size];[/b] echo "size='$cookie_font_size' "; } [i]echo ">"; echo "\$font[type] = $cookie_font_type<br>"; echo "\$font[size] = $cookie_font_size<br>"; echo "</font><br>"; echo "<b>Your form variables say:</b><br>"; echo "<font "; if ($_POST[type_sel]) { $post_type_sel = $_POST[type_sel]; echo "face='$post_type_sel' "; } if ($_POST[size_sel]) { $post_size_sel = $_POST[size_sel]; echo "size='$post_size_sel' "; } echo ">"; echo "\$type_sel = $post_type_sel<br>"; echo "\$size_sel = $post_size_sel<br>"; echo "</font>"; echo "</div></body></html>"; ?> I basically don't understand the following lines: if ($_COOKIE) { $cookie_font_size = $_COOKIE; and if ($_COOKIE[type]) { $cookie_font_type = $_COOKIE[type]; I understand that he makes the variables $cookie_font_type and $cookie_font_size each get their respective values, but where does he get "[type]" and "" from? They are not variable names for the font size or the font type, they aren't the names for the cookies themselves, ... so what values is he referring to? Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/128680-a-little-confused-about-cookies/ Share on other sites More sharing options...
beansandsausages Posted October 16, 2008 Share Posted October 16, 2008 i like cookies & also i like cake. but about your question, is he not refering to your browser font and size? correct me if i am wrong though. edit: looking at the script it seems as though you can define your own font and size from this array: $type = array("arial", "helvetica", "sans-serif", "courier"); $size = array("1","2","3","4","5","6","7"); Link to comment https://forums.phpfreaks.com/topic/128680-a-little-confused-about-cookies/#findComment-666899 Share on other sites More sharing options...
MoMoMajor Posted October 16, 2008 Author Share Posted October 16, 2008 i like cookies & also i like cake. but about your question, is he not refering to your browser font and size? correct me if i am wrong though. edit: looking at the script it seems as though you can define your own font and size from this array: $type = array("arial", "helvetica", "sans-serif", "courier"); $size = array("1","2","3","4","5","6","7"); Yes you can define your own font sizes and such but i don't understand where he gets the "" from in"$_COOKIE" and "$_COOKIE [type]" ... I also don't get if the and [type] parts are coming from the array variables ($type and $size) or the cookie names (font[type] and font). Link to comment https://forums.phpfreaks.com/topic/128680-a-little-confused-about-cookies/#findComment-666910 Share on other sites More sharing options...
revraz Posted October 16, 2008 Share Posted October 16, 2008 Another script sets the cookies, probably a user control panel script. Link to comment https://forums.phpfreaks.com/topic/128680-a-little-confused-about-cookies/#findComment-666961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.