Jump to content

How to catch Session Variable undifened exeption


Leftfield

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.