Create a login page With ajax and php

i want do create a login page With ajax and php. i with Edit code with some things done. But just does not work!?. After entering the user and page refresh the gets out . What there is solution that, user with page refresh not out ?
Comment give About to security Following code.
Please help me
Thank you

// Preload Images
img1 = new Image(16, 16);  

img2 = new Image(220, 19);  

// When DOM is ready

// Launch MODAL BOX if the Login Link is clicked

// When the form is submitted
$("#status > form").submit(function(){  

// Hide 'Submit' Button

// Show Gif Spinning Rotator

// 'this' refers to the current submitted form  
var str = $(this).serialize();  

// -- Start AJAX Call --

    type: "POST",
    url: "do-login.php",  // Send the login info to this page
    data: str,  
    success: function(msg){  
$("#status").ajaxComplete(function(event, request, settings){  
 // Show 'Submit' Button

// Hide Gif Spinning Rotator

 if(msg == 'OK') // LOGIN OK?
 var login_response = '<div id="logged_in">' +
     '<div style="width: 350px; float: left; margin-left: 70px;">' + 
     '<div style="width: 40px; float: left;">' +
     '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="images/ajax-loader.gif">' +
     '</div>' +
     '<div style="font-family: Tahoma; text-align: right;">'+
     "Welcome <a href='logout.php'>Logout</a>"+
     '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
     "You are successfully logged in! <br /> Please wait while you're redirected...<br /></div></div>";  
 $(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the 
setTimeout('go_to_private_page()', 3000); 
 else // ERROR?
 var login_response = msg;
// -- End AJAX Call --

return false;

}); // end submit event