Jump to content
Adamhumbug

Session Handling Sundefined Variable

Recommended Posts

I have a message bar that when a page reloads, a message appears at the top of the screen.

I feed the message with session variables that are set at the end of the action (submission for example)

When the page reloads the message displays and then unsets the session variables.

The issue is when the page first loads (when it has never run an action) and gives me the Notice: Undefined index: message.

My question is, how can i handle the session being blank when the page first loads and thus not get the notice.

Share this post


Link to post
Share on other sites

I think i have answered my own question about 10 seconds after posting this.

if(!empty($_SESSION['message'])){

doesnt seem to generate the same message that

	if($_SESSION['message'] !=''){

did

 

Thanks anyway

Share this post


Link to post
Share on other sites

A clearer test could be to use the "isset" function:

	if (isset($_SESSION['message']))
	echo $_SESSION['message'];
	

Share this post


Link to post
Share on other sites
17 hours ago, ginerjm said:

A clearer test could be to use the "isset" function:

 


	if (isset($_SESSION['message']))
	echo $_SESSION['message'];
	

 

Thanks for this.

Share this post


Link to post
Share on other sites

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.