Leftfield Posted February 6, 2011 Share Posted February 6, 2011 How can i catch this exception and run the catch code , and stop the error message displaying on the webpage . Thanks <?php try{ echo $_SESSION['btn']; } catch(Exception $ex) { $_SESSION['btn'] = "Check Available"; echo $_SESSION['btn']; } ?>"/> Please help Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/ Share on other sites More sharing options...
PaulRyan Posted February 6, 2011 Share Posted February 6, 2011 <?PHP session_start(); if(isSet($_SESSION['btn'])) { echo $_SESSION['btn']; } else { $_SESSION['btn'] = 'Check Available'; echo $_SESSION['btn']; } ?> Use that... Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170768 Share on other sites More sharing options...
Leftfield Posted February 6, 2011 Author Share Posted February 6, 2011 Thanks for the quick response ... it looks like it worked ! Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170770 Share on other sites More sharing options...
PaulRyan Posted February 6, 2011 Share Posted February 6, 2011 No problem, if you need anything just let us know Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170771 Share on other sites More sharing options...
Leftfield Posted February 6, 2011 Author Share Posted February 6, 2011 Nope there is still a problem I set my session like this <?php { if(isset($_SESSION['txt'])){//When is step through the code it goes to else telling me it is not set . $_SESSION['txt'] = "Next >"; echo $_SESSION['txt']; } else { $_SESSION['txt'] = "Check Available"; echo $_SESSION['txt']; } } ?> "/> But when i debug my code it tells me my session is not set And if i use session_start(); i get the following error Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\xampp\htdocs\OnlineBookingsPhp\index.php:199) in C:\Program Files\xampp\htdocs\OnlineBookingsPhp\index.php on line 210 Call Stack #TimeMemoryFunctionLocation 10.2265381640{main}( )..\index.php:0 24.1850394048session_start ( )..\index.php:210 Any ideas ??? Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170792 Share on other sites More sharing options...
BlueSkyIS Posted February 6, 2011 Share Posted February 6, 2011 you must use session_start() on any page that uses $_SESSION. you must NOT have any browser output before session_start(): no empty space, no HTML, no nothing going to the browser before session_start() Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170793 Share on other sites More sharing options...
Leftfield Posted February 6, 2011 Author Share Posted February 6, 2011 Ok it works without an error . But i am trying to set a button value to my session like so <input id="Submit" type="submit" name="submit" value="<?php echo $_SESSION['txt']; ?>"/></div> But the debugger still skips this line if(isset($_SESSION['txt'])){//When is step through the code it goes to else telling me it is not set . Maybe isset is lost after postback is there maybe a better way to do this or should i use it as a session is the only thing that remain after postback Link to comment https://forums.phpfreaks.com/topic/226902-how-to-catch-session-variable-undifened-exeption/#findComment-1170803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.