Mr world wide
Mr world wide

Reputation: 4814

Session variable is not working properly how can i improve

$_SESSION['profile_updated']="yes";

Settingup session variable.!

<div class="col-md-12">
<?php if(isset($_SESSION['profile_updated'])){ ?>
<div class="confirmationmsgssg">Profile Updated successfully.</div> 
<?php unset($_SESSION['profile_updated']); } ?>
<h3>Your personal info</h3>
</div>

I am trying to show the alert message by using session..

Actually this is a enhancement project i can not change the whole code because it is there in a lot pages

What actually happening with the code is first it is check in the view page like if $_SESSION['profile_updated'] is there show the message and it will automatically disappear after 3 second .. when i refresh the page that message should not appear because i have not updated anything for that i have to use unset..

It is working fine if i remove unset($_SESSION['profile_updated']); this unset. but when i add this I don't why it is not working

i have checked everywhere session_start(); is in my first line of php What could be the possible error..? I have tried with ob_start(); Didn't worked..!

Upvotes: 1

Views: 51

Answers (2)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

Your code looks perfectly fine to me.I don't know why this not worked.

try once with !empty and $_SESSION['profile_updated'] = ''

<div class="col-md-12"> 
    <?php if(!empty($_SESSION['profile_updated'])){ ?> 
        <div class="confirmationmsgssg">Profile Updated successfully.</div> 
        <?php $_SESSION['profile_updated'] = '';?>
    <?php  } ?> 
    <h3>Your personal info</h3> 

Note:-

make sure that session_start(); is there on top of your file

Try once with clearing cache and cookie and check with your original code.

Upvotes: 3

Lynda Carter
Lynda Carter

Reputation: 130

Clear the cookies and it has to work everything is right.

<div class="col-md-12">
<?php if(isset($_SESSION['profile_updated'])){ ?>
<div class="confirmationmsgssg">Profile Updated successfully.</div>
<?php unset($_SESSION['profile_updated']); } ?>
<h3>Your personal info</h3>
</div>

Upvotes: 3

Related Questions