PHP不重定向

I'm trying to write the logout of a website. When I do this I want the page to redirect to the login page. I think I'm doing it the correct way, but can't get the right result. Could you guys point me in the right direction?

Relevant Code:

<button onclick="logout()">Logout</button>

function logout()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.location=xmlhttp.responseText;
}
}
xmlhttp.open("GET","logout.php",true);
xmlhttp.send();
}

<?php
session_destroy();

header("Location:http://localhost:8888/loginns.html");

mysql_close($con);
?>

Thanks!

You are sending an ajax request to the page. But you are redirecting in the PHP script. That will have no effect.

You should redirect in the JavaScript after the ajax request like

window.location = 'http://localhost:8888/loginns.html';

Dont make the AJAX call.You are making an AJAX call to the logout page. PHP will return string as response. Make a standard call to logout.php and your code will work fine.

Well you have no redirect code in there like:

window.location.replace("/login");

Also might want to use a library such as MooTools or jQuery if you are going to do more Ajax.

This gives me an excuse to post my FAVORITE PHP script, EVER. It is superduper diabolical at heart… but it's a hooker with a heart of gold, really…

<?php   
    $cloaked = 'http://whereYouWantThemToGo.com';
    $real[] = 'http://whereTheyveBeenGoing.com';
    $location = $cloaked;
    header('Location: '.$location); 
?>

Why not just take user straight to logout.php <a href="logout.php">Logout</a>

#logout.php
session_unset();
session_destroy();
header('Location: login.php');