Tuesday, August 27, 2013

How to Logout Via php

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

       if (isset($_COOKIE[session_name()])) {
      setcookie(session_name(), '');
    }

    // Destroy the session
    session_destroy();
  }


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

------------

and for login via php

No comments:

Post a Comment

What You Think