0

I have normal php project in which each and every page not updating unless I press CTRL+F5.

Now biggest issues is I can not press CTRL+F5 on logout.php where I destroy my session. Hence again I redirect it to login. Session is getting destroy and redirecting to login page but it'll not update unless I press CTRL+F5.

logout.php

   $_SESSION['user_type']       ='';
   $_SESSION['balance']         ='';
   unset($_SESSION['balance']);
   unset($_SESSION['user_type']);
   session_destroy();
   echo '<script>window.location.href="login.php"</script>';
   exit(0);
halfer
  • 19,824
  • 17
  • 99
  • 186
yudi
  • 81
  • 1
  • 4

3 Answers3

1

When you want to destroy a session you still need to place session_start(); at the top of your page, otherwise session won't be destroyed correctly, also i would rather use header(); to redirect to login page instead of js

header("location: login.php");
Fabio
  • 23,183
  • 12
  • 55
  • 64
0

instead of echo '<script>window.location.href="login.php"</script>'; try using

header('location:login.php');

or

echo '<meta http-equiv="refresh" content="1;url=login.php">';
Karthick Kumar
  • 2,349
  • 1
  • 17
  • 30
  • Mr. Ganesh..Thanx for reply...but i tried using both JS AND header() it is redirecting but to login.php...and on login.php i'm print_r($_SESSION). this ll show session for 1st time and if i press CTRL+F5 it ll display blank array – yudi Feb 27 '14 at 08:22
  • Echoing a `` refresh tag on its own is not good practice - this should be enclosed in a valid HTML document. – halfer Feb 05 '16 at 19:46
0

Use header('location:login.php'); to redirect you page after session_destroy();