c-o-d-e Posted January 27, 2010 Share Posted January 27, 2010 I have a login form, and when I put in the correct details, and click submit, nothing happens... the page refreshes, but I get no error, and neither do I get logged in. Instead of refreshing the page, so still on the page where nothing happened, I try login again. It then works. Although normally, when a user gets logged in, it uses $back = $_SERVER['HTTP_REFERER']; header("Location: $back"); When having this is, I get an error.. Warning: Cannot modify header information - headers already sent by (output started at /home/jeanie/public_html/login.php:12) in /home/jeanie/public_html/login.php on line 120 Maybe both the issues are related and when one is fixed the other will be too. It's probably a simple issue, but I haven't figured it out yet. Here is the full code. <?php session_start(); include ("inc/config.php"); include("inc/functions.php"); checkcookie(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-UK" > <meta name="description" content="Developer's Community is a community dedicated to learning and teaching specific areas around computer development. We have a wide range of tutorials that cover all topics and we also have support forums for those who are needing a bit of support. The forums also consists of freelancing, and general discussions." > <title>Developer's Community - Login</title> <link href="styles/main.css" rel="stylesheet" type="text/css" /> <link href="styles/support.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="images/favicon.ico"> <link rel="icon" href="images/favicon.ico"> <script type="text/javaScript" src="inc/cona.src.js"></script> <?php background(); ?> <script type="text/javaScript" src="inc/cona.src.js"></script> </head> <body> <!-- Begin Page --> <div id="container"> <!-- Header --> <div id="header"> <?php members_template(); ?> </div> <!-- Navigator --> <div class="navigator" id="dropdown"> <ul id="topnav"> <li><a href="/">Home</a></li> <li><a href="about.php">About</a></li> <li><a href="tutorials.php" rel="tutorials">Tutorials</a></li> <li class="active"><a href="support.php" rel="support">Support</a></li> <li><a href="forums">Forums</a></li> <li><a href="feeds">Feeds</a></li> </ul> </div> <?php navigator(); ?> <script type="text/javascript"> cssdropdown.startchrome("dropdown") </script> <div id="subnavigation"></div> <!-- Main Content --> <div id="pageContent"> <div id="advertskyscraper"> <script type="text/javascript"><!-- google_ad_client = "pub-7463512441958618"; /* 160x600, created 03/01/10 */ google_ad_slot = "6049830800"; google_ad_width = 160; google_ad_height = 600; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></div> <div id="fill"><center> <h1>Login</h1> <p>This login is not the same as the Forums. It's a seperate account temporarily, you may have to <a href="register.php">register</a>. <?php if(isset($_POST['login'])) { $username = trim(addslashes(mysql_real_escape_string($_POST['username']))); $password = md5(trim(mysql_real_escape_string($_POST['password']))); // Are the fields empty? if(empty($username)){ $error['username'] = '*'; } if(empty($password)){ $error['password'] = '*'; } // We then check if the user is banned $q = mysql_query("SELECT ExpireDate FROM Banned WHERE Username = '$username'") or trigger_error('Query failed: '.mysql_error()); if(mysql_num_rows($q) !=0){ $row = mysql_fetch_array($q); if($row['ExpireDate'] > time()){ $error['banned'] = 'You are banned until '.date("d/m/Y H:i:s", $row['ExpireDate']).'!'; } else { $query = mysql_query("DELETE FROM Banned WHERE username = '$username'") or trigger_error('Query failed: '. mysql_error()); } } // Now we check if the username or password entered is incorrect and if correct check if they are activated $query = mysql_query("SELECT * FROM Users WHERE Username = '$username' AND Password = '$password' LIMIT 1") or trigger_error('Query failed: '. mysql_error()); $row = mysql_fetch_array($query); if(mysql_num_rows($query) == 0){ $error['incorrect'] = 'Your username or password is incorrect. Please try again.'; } elseif($row['Activated'] == 0){ $error['activated'] = 'Your account is not activated.'; } // If no errors were found, continue with the login if(!isset($error)){ $row = mysql_fetch_array($query); $query = mysql_query("UPDATE Users SET Used = YEAR(CURDATE()) WHERE username = '$username'") or trigger_error('Query failed: '. mysql_error()); $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; if(isset($_POST['keep']) == checked){ $actkey = $row['Actkey']; $activated = $row['Activated'] > 0; $time = time() + 60*60*24*1000; setcookie(DC_5739487932, $username, $time); setcookie(DC_9640683492, $actkey, $time); setcookie(DC_2094892587, $activated, $time); } $back = $_SERVER['HTTP_REFERER']; header("Location: $back"); } else { $error['failed'] = 'There was an error processing your login, please try again'; } } ?> </p> <?php echo ''.$error['activated'].''.$error['banned'].''.$error['incorrect'].''.$error['failed'].''; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" style="width:200px; margin:0 auto;"> <label>Username<?php echo $error['username']; ?> <input name="username" type="text" class="textBox" id="username" /></label> <label>Password<?php echo $error['password']; ?> <input name="password" type="password" class="textBox" id="password" /></label> <br /><label><input name="keep" type="checkbox" id="keep" />Keep Me Logged In<br /></label><br /> <input name="login" type="submit" class="textBox" id="login" value="Submit" /> </form> <p>Didn't get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p> <p>Need an account? <a href="register.php">Click here</a> to register, it's completely free! </p> <br /> </center></div> </div> <!-- Footer --> <div id="footer"> <?php footer(); ?></div> <!-- end Page --></div> <?php include_once("inc/analytics.php") ?> </body> </html> This uses function.php with some functions. The top bit of that file is.. session_start(); include("config.php"); Can you help? Quote Link to comment Share on other sites More sharing options...
schilly Posted January 27, 2010 Share Posted January 27, 2010 it sounds like you're login is working fine. when you use the header() fn you can't echo anything to the browser before it gets called. So you need to put your whole login code block above your html. your HTTP_REFERER may be putting you back to the same page as well as the POST came from your login page so you probably want to set that variable before the form submit. Quote Link to comment 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.