Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

php session error

why session is unavailable to the page when i use unset after echo it (session). and when i comment unset(), then i am able to see it on the page ? what's issue with it :( my code

<div class="fixed bg-blue-500 text-white py-2 px-4 rounded-xl bottom-3 right-3">test
    <?php if(isset($_SESSION['register'])) :?>
    <span class="session fixed bg-blue-500 text-white py-2 px-4 rounded-xl bottom-3 right-3">
        <?php echo $_SESSION['register']; ?>
    </span>
    <?php  unset($_SESSION['register']) ?>
    <?php endif ?>
</div>
0 likes
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

@shivamyadav Try this:

<div class="fixed bg-blue-500 text-white py-2 px-4 rounded-xl bottom-3 right-3">test
    <?php if(isset($_SESSION['register'])) :?>
    <span class="session fixed bg-blue-500 text-white py-2 px-4 rounded-xl bottom-3 right-3">
        <?php echo $_SESSION['register']; ?>
    </span>
    <?php endif ?>
</div>

<?php unset($_SESSION['register']) ?>

Please or to participate in this conversation.