Jump to content

<meta> vs <head> help needed \= redirecting problems >.<


Minimeallolla

Recommended Posts

How would I redirect  if the code is after the <head> tag?

My code is a bit complicated and needs to go under my html code but wont redirect successfully because of <head>.

I'm using

 print("<meta http-equiv='Refresh' content='0;index.php' />"); 

to redirect.

Link to comment
https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/
Share on other sites

 

 

					<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
				"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<?php
include ("information.php");
?>

<title> MySite - Log in</title>
<?php
include ("background.php");
?> 

</head>
<body>
<div class="header">
	<div class="headertext">

<a href="/index.php">Home</a>
<a href="/register.php">Register</a>
<a href="/games.php">Games</a>
<a href="/aboutus.php">AboutUs</a>

</div>
		<div class="logo">

<a href="/index.php"><img src="/images/mysite.png" alt ="MySite"></a><br>

	</div>
		</div>
			<div class="main">

<div align="center"><b>Log in</b>
<form  action="" method="post">
<table class="centered" border="0">
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr></table> 
</form></div>

<?php 
// Connects to your Database 
include ("database.php"); 

// Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']));
{
$username = ( $_COOKIE['ID_my_site'] ); 
$pass = ( $_COOKIE['Key_my_site'] );	
$check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) 	
	{
if ($pass == $info['password']) 
print("<meta http-equiv='Refresh' content='0;index.php' />");
	}
}

// If the login form is submitted 
if (isset($_POST['submit']))
{ 

// Checks if they filled it in
if(!$_POST['username'] | !$_POST['pass'])
die('<center>You did not fill in a required field!</center>');

// Secures input
if (!get_magic_quotes_gpc())
$_POST['email'] = mysql_real_escape_string(stripslashes(trim($_POST['email'])));
$_POST['username'] = mysql_real_escape_string(stripslashes(trim($_POST['username'])));
$_POST['pass'] = mysql_real_escape_string(stripslashes(trim($_POST['pass'])));

// Checks it against the database
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

// Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0)
die('<center>Account does not exist! Please register first.</center>');
while($info = mysql_fetch_array( $check )) 	
	{
$password= mysql_real_escape_string(stripslashes(trim($_POST['password'])));
$pass= mysql_real_escape_string(stripslashes(trim($_POST['pass'])));
$salt = 's+(_a*';
$_POST['pass'] = md5($_POST['pass'].$salt);

// Gives error if the password is wrong
if ($_POST['pass'] != $info['password'])
die('<center>Invalid username or password!</center>');
else 

		{ 
// If login is ok then add a cookie 
$username= mysql_real_escape_string(stripslashes(trim($_POST['username'])));
$hour = time() + 3600; 
setcookie("ID_my_site", $_POST['username'], $hour); 
setcookie("Key_my_site", $_POST['pass'], $hour);	 

// Redirect them
if ($pass == $info['password'])
print "Log in Successful!";
print("<meta http-equiv='Refresh' content='0;index.php' />");
		} 
	} 
}  
?> 

			</div>
				<div class="footer">
					<div class="footerleft">



				</div>
						<div class="footerright">



					</div>
							</div>
</body>
</html>

 

I want the errors to go under the registration form and for that, the registration form must be at the top, interferring with the <head> and <meta>  >.< I know die is not the best thing to use but i really cant figure out a working error function \=

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.