Search code examples
phpsessionvariablesunset

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..!


Solution

  • 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>