Hkm Sadek Hossain Hkm Sadek Hossain - 4 months ago 10
PHP Question

logging out is not working in live server godaddy

I have written a few lines of code in php that helps a user to logout. It works in localhost but in live server the system doesn't logout the users. Could you please help whats wrong with the code?

<?php
session_start();
$_SESSION['uid']='';
$userData='';
$cookie_name="user";
$out=session_destroy();
if($out)
{
$url=$base_url.'index.php';

setcookie($cookie_name, $cookie_value, time() - (3600), "/");
// 86400 = 1 day
echo "<script>window.location='$url'</script>";
}


?>

Answer

Try this on your live server:

<?php
  // session_start() should be at the to of your file
  session_start();

  $_SESSION['uid'] = '';
  unset($userData);

  $cookie_name = "user";

  if(session_destroy()) {
    $url = $base_url . 'index.php';

    setcookie($cookie_name, $cookie_value, time() - (3600), "/");
    unset($_COOKIE[$cookie_name]);

    echo "<script>alert($_COOKIE[$cookie_name])</script>";

    //echo "<script>window.location='$url'</script>";
  }