weasel2006 Posted May 13, 2008 Share Posted May 13, 2008 I am using this code to check if there is any data inside of $_SESSION['fcode'] if not redirect back to index.php. If data exsists, show the data then unset the session variable. session_start(); //Error Handling if(!isset($_SESSION['fcode']) ) { header('Location: index.php'); die(); } else{ echo ($_SESSION['fcode']); unset($_SESSION['fcode']); } However no matter what I do, the var will not unset after the echo. It will unset if I place the unset code before the echo but not after. The idea is, if anyone tries to access the page without any data in the var then they are redirected. It is part of an error page, where they are taken to for form errors, then shown the errors and then have the errors in the session cleared so they cant return or access the page again and no one from outside can get to the page directly. How do I know it's not unsetting? I can navigate away and return with the same message echoing out. I'm hoping some one can help! Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/ Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 What browser are you using, and were you just hitting "Back"? Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/#findComment-540309 Share on other sites More sharing options...
radar Posted May 13, 2008 Share Posted May 13, 2008 session_unset('fcode'); try that. Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/#findComment-540310 Share on other sites More sharing options...
weasel2006 Posted May 13, 2008 Author Share Posted May 13, 2008 Hi guys, thanks for taking the time and trouble to reply, much appreciated! @DarkWater: I've tested both IE7 and FF and they're both the same. No, not pressing back.. I can navigate to another url on my site and then type in the url to the error page and it's still displaying the same message. The code will work if I try and go directly to the error page straight after launching my browser (new session) but once an error message has been set it wont unset after displaying it. @radar: Thanks, I tried that code but it didn't work It's really baffling me ??? Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/#findComment-540321 Share on other sites More sharing options...
radar Posted May 13, 2008 Share Posted May 13, 2008 Baffling me too. i use almost the exact same setup for my websites... ie code below.. <?php if( $_SESSION['admin']['intime'] < time() - 1800 && $_action != 'login') { session_unset('admin'); $interface = 'login.tpl'; $aws->assign('errMsg', 'ERROR: Session expired. Please login again.'); }elseif ($_SESSION['admin']['intime'] == '' && $_action != 'login') { session_unset('admin'); $interface = 'login.tpl'; $aws->assign('errMsg', 'ERROR: You must be logged in, in order to access the administration panel'); } else { # all my pages code below } ?> Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/#findComment-540328 Share on other sites More sharing options...
weasel2006 Posted May 13, 2008 Author Share Posted May 13, 2008 Maybe if I explain how I did my site, it may shed some light and jog some ideas? I'm new to php and they way I did my site was like this: My urls are set up like this.. index.php?view=page Index.php has a header and footer and a div in the middle which calls a view.php. View.php's job is to call and display content stored in the database, but because I dont fully understand php let alone oop what I did was to store my content layout divs etc and passed the lot through htmlentities before storing them. So when view.php calls the content it has to decode the lot then show it and it shows the content layout as it should be rather than as a load of code. My error page is the same but has a php include in it and this posed a problem so I used this: $result = eval("?>" . htmlspecialchars_decode($result) . "<?php ;"); because it wasn't parsing the php but instead outputting the code. The php include calls a common_errors.php which has the code that I'm having trouble with. I'm wondering if any of this is causing the problem along the way? If it helps, I can post code as needed. Link to comment https://forums.phpfreaks.com/topic/105491-my-session-wont-unset/#findComment-540360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.