Minimeallolla Posted December 2, 2010 Share Posted December 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/ Share on other sites More sharing options...
trq Posted December 2, 2010 Share Posted December 2, 2010 Re-organie your code. Think about it, why output any html if all your going to do is redirect the user to another page. Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142149 Share on other sites More sharing options...
Minimeallolla Posted December 2, 2010 Author Share Posted December 2, 2010 I might be a noob but im not That nooby lol. Im using an if function >.< Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142157 Share on other sites More sharing options...
trq Posted December 2, 2010 Share Posted December 2, 2010 There is no such thing as an 'if' function. Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142167 Share on other sites More sharing options...
Minimeallolla Posted December 2, 2010 Author Share Posted December 2, 2010 <?php  if ( $_POST['username'] != 'thorpe' ) { die (" if function? ");  ?> Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142172 Share on other sites More sharing options...
trq Posted December 2, 2010 Share Posted December 2, 2010 if is a control structure. Its part of the language itself. Â Besides, you still need to rearrange your code. Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142175 Share on other sites More sharing options...
Minimeallolla Posted December 2, 2010 Author Share Posted December 2, 2010   <!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 \= Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142178 Share on other sites More sharing options...
litebearer Posted December 2, 2010 Share Posted December 2, 2010 SInce the form is submitting to itself, perhaps you need to place your PHP stuff BEFORE you output the form Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142182 Share on other sites More sharing options...
Minimeallolla Posted December 2, 2010 Author Share Posted December 2, 2010 but the die ( ) is in the php and it will be echoed above the form and look bad lol im going to make a thread about the die ( ) code, i need a proper error function. Quote Link to comment https://forums.phpfreaks.com/topic/220448-vs-help-needed-redirecting-problems/#findComment-1142184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.