I wondered if someone could explain how to pass a value through a link using cookies to store the data. For instance, I have a quiz with four possible answers and each one has a value associated with it. The value associated with the answer that the user clicks needs to be stored in the cookie. Here is an example: What is your favorite color in the rainbow? Yellow (value=1) Red (value=2) Orange (value=3) Blue (value=4) So if the user clicks orange the integer 3 needs to be stored in a cookie, and the quiz would progress to the next question. Any help would be appreciated. Thanks!
I think you need to create a script which would generate cookie after clicking on one of those links. <a href="cookie.php?value=1">Yellow</a> cookie.php - create cookie
Thanks for your help...btw you have an array error on your mousepads website in your sig: http://www.hotmousepads.com/Other/DALMATION-20FACES-Large-Mouse-Pad-NEW-8306/
Thank You You dont know regular expressions by the chance ? =) Need solution: http://forums.digitalpoint.com/showthread.php?t=1187231
I would store the values in a session instead. With cookies, with every page that the user requests all the values stored in the cookies will be passed to the server, which would be a waste of bandwidth (and therefore speed).
using sessions is definitely the best option, heaps of info out there in googleland. Basically at the top of your php script you want to include the code session_start(); and then on the 2nd page if you want to know the answer submitted from first page you would just need to use $_SESSION[rainbow] or whatever the input name of the form element was.
you can use both session or cookie. you can do something like this: // define variable if($_GET['color'] == 'Yellow') { $color = 1; } elseif ($_GET['color'] == 'Red') { $color = 2; } elseif ($_GET['color'] == 'Orange') { $color = 3; } elseif ($_GET['color'] == 'Blue') { $color = 4; } if(!empty($var)) { setcookie("chosen_color", $var, time()+60*60*24*7); // this will save the color value in cookie, it will be saved for 1 week } PHP: you can fill the value in a variable using $_GET or $_POST command. the above code will work if you send the link this way: you.com/page.php?color=Yellow to fetch the cookie value, do something like this. if(isset($_COOKIE['chosen_color'])) { echo "The cookie value is: ".$_COOKIE['chosen_color']; } PHP: i hope this helps.
I think your answer is available in your question. As others i can say that using session will be better way for storing value and then append the new page value into your array with previous values. at the end you will get all values in your array. ------------------------------------------------------------------ Precious Interview News Download Free Ebooks