PHP Refresh Login Box

I have a page, my index, that I put a login box on. Now, when the user logs in on that login box, I want it to refresh within the box… Does this make sense? How do I do it?

Here is my header:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<link href="style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo($title); ?></title>

<div id="header"></div>
<div id="content_wrapper">

<ul id="navbar">
	<li><a href="#">Home</a></li>
    <li><a href="#">Community</a></li>
    <li><a href="#">Purpose</a></li>
    <li><a href="#">Contact Us</a></li>
<div id="content-top"></div>
<div id="content-bottom">

<div id="login">
} else { 

So, I have the DIV, and if the session is registered, it should go to main.php, however it doesn’t open in the box, it opens in a new webpage. Get what I’m saying?


You mean that you don’t want to refresh the whole page?

In that case, you might want to look at AJAX. That’ll require quite a bit of scripting, but it can be used to replace the contents of the div with id login with the contents of main.php.

On a side note i wouldn’t recommend using session_is_registered anymore, instead use the super global $_SESSION to check for sessions vars.

You can do what you want without ajax because the logic in your IF block is fine.

I suspect the code in your login.php is causing the problem either by not redirecting back to your index.php correctly or because of some other logic error.

Also session_is_registered is deprecated from PHP5.3.

It’s better to use something like

if(isset($_SESSION['myusername'])) {
     //do something

Post the code in login.php so we can see if there is a problem there.