fishbaitfood Posted July 28, 2010 Share Posted July 28, 2010 Hey phpfreaks, I have a session, to add words to an array. But my session_destroy() won't work at the end! This is my code: //at the very top of my index.php <?php session_start(); header('Content-type: text/html; charset=UTF-8'); ?> //then some html and javascript code (not affecting my array) //........ //........ //then my actual form and php code, for adding a word to an array <form id="arrayForm" method="post" action="index.php"> <input type="text" name="word" maxlength="12" /> <input class="btn" type="submit" name="submit" value="submit" /> <input class="btn" type="reset" name="reset" value="clear array" /> </form> <p> <?php function sanitize($input) { if (!empty($input)) { $input = strip_tags($input); $input = htmlentities($input); return trim($input); } else { return FALSE; } } if (isset($_POST['submit'])) { $word = $_POST['word']; if (sanitize($word)) { $_SESSION['words'][] = $word; //display words in array - this works for($i=0; $i < count($_SESSION['words']); $i++){ echo $_SESSION['words'][$i] . " "; } } else { echo 'Please enter a word'; } } //the below won't work elseif (isset($_POST['reset'])) { $_SESSION['words'] = ''; unset($_SESSION['words']); session_destroy(); } ?> </p> Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/ Share on other sites More sharing options...
AbraCadaver Posted July 28, 2010 Share Posted July 28, 2010 How do you know it "doesn't work" and what does that mean? Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/#findComment-1092180 Share on other sites More sharing options...
fishbaitfood Posted July 28, 2010 Author Share Posted July 28, 2010 How do you know it "doesn't work" and what does that mean? because if I add another word, after I pressed the reset button, the previous words still appear.. It should be ONE new word.. It just seems that my 'reset' button doesn't work, but I used it just like my 'submit' button, only difference is that it "clears" the array.. which it doesn't.. Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/#findComment-1092182 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 An input type="reset" doesn't actually send anything to the server. It simply resets the form dynamically without any http requests. You need to send information to the server telling it to reset. Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/#findComment-1092184 Share on other sites More sharing options...
AbraCadaver Posted July 28, 2010 Share Posted July 28, 2010 An input type="reset" doesn't actually send anything to the server. It simply resets the form dynamically without any http requests. You need to send information to the server telling it to reset. Yes, so something like this with your existing code: <input class="btn" type="submit" name="reset" value="clear array" /> Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/#findComment-1092187 Share on other sites More sharing options...
fishbaitfood Posted July 28, 2010 Author Share Posted July 28, 2010 doh! ofcourse, thank you guys! edit: got it working now Link to comment https://forums.phpfreaks.com/topic/209119-session_destroy-not-working/#findComment-1092190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.