2

I want to let an alert box pop up after a user's session expire. My problem is I can't the alert box isn't displaying.

The alert box isn't working if I put the unset session but it'll work if there is no unset session. I know using alert('') isn't ideal so I'm wondering if there's a simple way to create such pop up.

My code is something simple like this

echo "
<script>
alert('Your Session has expired for inactivity. Please log in again');
</script>";
unset($_SESSION['admin_log']);
unset($_SESSION['admin_time_log']);
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
paradoxparabola
  • 73
  • 1
  • 10
  • Javascript runs on the browser, PHP runs on the server, so the javascript code will never be run until the PHP script has completed – RiggsFolly Nov 12 '16 at 03:52
  • You might want to take a look at this article: [Alert user if session is going to expire, option to renew session](http://stackoverflow.com/questions/3858120/alert-user-if-session-is-going-to-expire-option-to-renew-session) [PHP/Javascript Session Timeout with warning](http://stackoverflow.com/questions/11538803/php-javascript-session-timeout-with-warning) – Sarah Nov 12 '16 at 03:56
  • Your entire thinking pattern is wrong. It's as though you try to teach a baby that hasn't been borne yet how to walk. – Angel Politis Nov 12 '16 at 04:03

1 Answers1

0
?>
<script>
alert('Your Session has expired for inactivity. Please log in again');
</script>
<?php
unset($_SESSION['admin_log']);
unset($_SESSION['admin_time_log']);
?>

Try this way. This work. It is working in my case.

Pranav MS
  • 2,235
  • 2
  • 23
  • 50