Logout not working

Hi this logout script is not working for me, the user remains logged on even after the logout script runs, is there anything out of place here?

<?php
  // If the user is logged in, delete the session vars to log them out
  session_start();
  if (isset($_SESSION['user_id'])) {
    // Delete the session vars by clearing the $_SESSION array
    $_SESSION = array();

    // Delete the session cookie by setting its expiration to an hour ago (3600)
    if (isset($_COOKIE[session_name()])) {
      setcookie(session_name(), '', time() - 3600);
    }

    // Destroy the session
    session_destroy();
  }

  // Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
  setcookie('user_id', '', time() - 3600);
  setcookie('username', '', time() - 3600);

  // Redirect to the home page
  $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
  header('Location: ' . $home_url);
?>

Are you sure $_SESSION[‘user_id’] is set when you call this code? If it isn’t, the logout code won’t be executed.

Also, why are you storing the user_id and username in separate cookies? Why not put them in the session?

Right after,
session_start();

Put in,
echo '<pre>Session '; print_r($_SESSION); echo ‘</pre>’;

You should see user_id -> joe or something like that. This will give you a starting point to debug.

Also be generous and echo all expected values where you want them.

After if (isset($_SESSION[‘user_id’])) {. . . . . . . } put in an else statement and echo out “session is not set”.