goatdog Posted March 5, 2009 Share Posted March 5, 2009 ok i want to know the best way to do this. Now this is without using forms which would make it easy. let's say there's a directory listing, you view one of the items in the directory and you want to delete it, so you hit the delete button, it deletes the item and redirects you back to the directory listing, but at the top of that listing i want it to show a message to the user saying, the item has been successfully deleted now the only way that i can think of doing this is with sessions, but is that the best way? set the session in the delete clause if(isset($_REQUEST['delete_item'])){ //delete query here $_SESSION['message'] = "item successfully deleted"; header("location:directory listing"); //then on the main page if(isset($_SESSION['message']){ echo $_SESSION['message'] ; unset($_SESSION['message'] ); does that look like a proper way to do it or do you have a better suggestion? thanks Link to comment https://forums.phpfreaks.com/topic/148086-passing-a-message-variable-on-a-header-redirect/ Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 yup, sessions is the way i usually do it. the only other other good option is to pass a key that refers to a message as a GET variable. so, keep a list of messages somewhere in an associative array like this: <?php $messages = array( 'delete_success' => 'Item successfully deleted', 'delete_fail' => 'Failed to delete item', ); ?> then in your redirect: header("location:directorylisting.php?msg=delete_success"); then on your directory listing you can look up the text for the message. again, i prefer the SESSION option, but this is an alternative Link to comment https://forums.phpfreaks.com/topic/148086-passing-a-message-variable-on-a-header-redirect/#findComment-777322 Share on other sites More sharing options...
goatdog Posted March 5, 2009 Author Share Posted March 5, 2009 thanks, the array is a good idea for multiple messages, but would it repeat if the page is refreshed? with the session it gets unset so you can refresh the page and it won't show again Link to comment https://forums.phpfreaks.com/topic/148086-passing-a-message-variable-on-a-header-redirect/#findComment-777340 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 yes, it would still show Link to comment https://forums.phpfreaks.com/topic/148086-passing-a-message-variable-on-a-header-redirect/#findComment-777351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.