# Session variable to hide/unhide button

**URL:** <https://www.phphelp.com/t/session-variable-to-hide-unhide-button/35415>\
**Category:** Javascript & Ajax\
**Created:** [April 24, 2023, 6:54am UTC](https://www.phphelp.com/t/session-variable-to-hide-unhide-button/35415 "2023-04-24T06:54:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![randelll](https://www.phphelp.com/user_avatar/www.phphelp.com/randelll/32/4165_2.png) [@randelll](https://www.phphelp.com/u/randelll)\
**Post date:** [April 24, 2023, 6:54am UTC](https://www.phphelp.com/t/session-variable-to-hide-unhide-button/35415/1 "2023-04-24T06:54:32Z")

</div>

I wish to use a session variable to hide a button that is in a column of 8 buttons. I have tried the following PHP code:

```auto
        <?PHP
            if($_SESSION['user_pkey']==1){
        ?>
              <button class = "btn btn-info btn mt-2 my_specialbtn btn-lg" onclick="document.location='volscontactinfodirectory.php'">Add Database User</button>
        <?PHP }
        ?>
```

I wan t this button to display if ‘pkey’ is 1 else hide it.

How do I do this?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [April 24, 2023, 11:10am UTC](https://www.phphelp.com/t/session-variable-to-hide-unhide-button/35415/2 "2023-04-24T11:10:04Z")

</div>

Why don’t you just do in JavaScript?

```auto
var specialBtn = document.querySelector('.my_specialbtn');

specialBtn.addEventListener('click', function() {
  if (specialBtn.style.display === 'none') {
    specialBtn.style.display = 'block';
  } else {
    specialBtn.style.display = 'none';
  }
});

```
