Jump to content

[SOLVED] Page refresh issue...


VirusDoctor

Recommended Posts

Hi guys, I've designed my login page for one of my new scripts. The problem is that I'd like the script to display a message "You are now logged in" and then after about 3 seconds, change to the main page after login. It currently doesn't do it. Could anyone assist as to how this can be done?

 

I've tried using header("Location: template.php"); but it doesn't seem to be working and I cant figure this out on my own. Here is the code for the login.php page.

 

<?php
session_start();
// Start the session login timer.
$start=time();
$_SESSION['time_start']=$start; 


// We check to see if a session is or isn't active.
if (!isset($_SESSION[my_loginstatus]))

{
require_once("std_config.php");
require_once("header.php");
require_once ("php/qry_mngr.php");

// If the user clicks login...

if(isset($_POST['login']))

{

		$username = trim(addslashes($_POST['username']));
		$password = md5(trim($_POST['password']));

		$query = mysql_query("SELECT * FROM users WHERE username = 
		'$username' AND password = '$password' LIMIT 1") or die(mysql_error());

		$row = mysql_fetch_array($query);

if(mysql_num_rows($query) > 0)
{

		// Check if the users account is activated, if it is, log them in and set some session variables.
if ($row['activated'] > 0)
		{

			$_SESSION[my_loginstatus] = 'true';
			$_SESSION['username'] = $username;
			$_SESSION['name'] = $row['name'];
			echo ("<br><div class='notice'>Welcome ".$row['name'].", You are now logged in.</div><br>");
			mysql_query("UPDATE users SET logged_in='1' WHERE logged_in='0' 
			AND username='$username'") or die (mysql_error());	
			header("Location: template.php");			
		}

	else
  			{

			echo '<p class="error">Sorry, you must activate your account first. 
			Please check your email for the email.</p>
					<p>Didn'."'".'t get your validation email? 
					<a href="resend.php">Click here</a> to resend the validation email.</p>';
		}

} 
	else 
		{

			echo '<br><p class="error">There was an error processing your login, 
			it appears that your username and/or password was incorrect. Please try again.</p>
				<p class="notice">Didn'."'".'t get your validation email? 
				<a href="resend.php">Click here</a> to resend the validation email.</p><br>';
		}

} 
	else 
		{

?>
<br>
     
    <div class="error">
        Please Login to access your Members Area:
    </div>
    <br>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <br>

        <table class="loginTable" border="1">
            <tr>
                <td class="bgcolor">Username:</td>

                <td class="inputbox"><input class="textinput" type="text" name="username" value="<?php if(isset($_POST['username'])) { print $_POST['username']; }?>" size="17"></td>
            </tr>

            <tr>
                <td class="bgcolor">Password:</td>

                <td class="inputbox"><input class="textinput" type="password" name="password" value="" size="17"></td>
            </tr>
        </table>
        <br>
         
        <div>
            <input class="buttons" name="login" type="submit" id="login" value="Login">
        </div>
    </form>
    <br>
     
    <div class="notice">
        Didn't get your validation email? <a href="resend.php">Click here</a> to resend the validation email.
    </div>
    <br>
     
    <div class="notice">
        Need an account? <a href="register.php">Click here</a> to register, it's completely free!
    </div>
    <br>
<?php } 

require("footer.php");
}

else
{
header("Location: template.php");

}

?>

Link to comment
Share on other sites

Hi Adam, I realize that, it seems like it has to do with the way I designed the login script, using the If and Else statements where I have them prevents me from sending header info wherever I want it.

 

I just cant think of how to get around this though or where to play the header info for it to work only once a users login is ok.

 

Shaun

Link to comment
Share on other sites

Hey guys, thanks for all the help.

 

The meta refresh is what worked perfectly for what I'm trying to do, thanks Adam!

 

Rajiv, the reason why your fix didn't work is because in my header.php there's quite a bit of stuff going on in there, so when I added it to the isset login block, it made the whole page no longer function.

 

Fortunately the problem is solved now though, thanks again guys.

 

Shaun

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.