php refresh problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmallia
Forum Commoner
Posts: 25
Joined: Sat Nov 19, 2011 3:18 pm

php refresh problems

Post by dmallia »

I made this script.

Code: Select all

<?php
	if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{

			if ($info['status'] == 0)
				{
					echo "<meta http-equiv='refresh' content='index.php'>";
					include('start.php');
				}
			else
				{
					echo "<meta http-equiv='refresh' content='index.php'>";
					include('stop.php');
				}

		}
	elseif(!empty($_POST['username']) && !empty($_POST['password']))
		{
			$username = mysql_real_escape_string($_POST['username']);
			$password = md5(mysql_real_escape_string($_POST['password']));
    
			$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
    
			if(mysql_num_rows($checklogin) == 1)
				{
					$row = mysql_fetch_array($checklogin);
					$email = $row['EmailAddress'];
					$_SESSION['Username'] = $username;
					$_SESSION['EmailAddress'] = $email;
					$_SESSION['LoggedIn'] = 1;

					echo "<meta http-equiv='refresh' content='0;index.php'>";
				}
			else
				{
					echo "<h1>Error</h1>";
					echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>";
				}
		}
	else
		{
?>
			<h1>Member Login</h1>
			<p>Please either login below, or <a href="register.php">click here to register</a>.</p>
    
			<form method="post" action="index.php" name="loginform" id="loginform">
				<fieldset>
					<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
					<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
					<input type="submit" name="login" id="login" value="Login" />
				</fieldset>
			</form>
    
<?php
		}
?>
now the problem is that when a user loges it moves to this script.

Code: Select all

			if ($info['status'] == 0)
				{
					echo "<meta http-equiv='refresh' content='index.php'>";
					include('start.php');
				}
			else
				{
					echo "<meta http-equiv='refresh' content='index.php'>";
					include('stop.php');
				}
and the page keeps refreshing.

I know that it's is keeping executing this everytime

Code: Select all

echo "<meta http-equiv='refresh' content='index.php'>";
How can i do a 1 refresh and than the page stops.

Thanks before hand.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php refresh problems

Post by social_experiment »

Code: Select all

<?php
 echo '<meta http-equiv="Refresh" content="10;url=index.php" >';
?>
This reloads your page after 10 seconds then stops.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply