June 27, 200818 yr Hallo I am very much a newbie when it comes to php and MySQL please keep that in mind. http://adriaanvm.com/archives/howto-create...gin-form-in-php I followed the above howto to create a simple login and registration form. Now I got two problems. 1. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\go\connection.php:2) in C:\xampp\htdocs\go\login2.php on line 6 Success! You are now logged in newb I have read is a very common error but I would appreciate if you could point it out to me anyway. 2. When I login, I get”Success! You are now logged in newb” which is fine. The problem is that I actually don’t know how to redirect the login to another page. I assume I would have add the URL in the php code like I would do with either HTML or CSS. Hope you can help me out any pointer to documentation would be cool too. Thanks.
June 27, 200818 yr 'headers already sent' can mean that you have line breaks at the beginning or end of your file.
June 27, 200818 yr Author wow, that was exactly it, but I think the blank line was in connection.php (the first line was blank) which is called from login2.php Thanks This is where I login. <!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" /> <title>login</title> <link rel="stylesheet" type="text/css" href="style_login.css"> </head> <body> <div class="site"> <div> <b class="sitebox"> <b class="sitebox1"><b></b></b> <b class="sitebox2"><b></b></b> <b class="sitebox3"></b> <b class="sitebox4"></b> <b class="sitebox5"></b></b> <div class="siteboxfg"> <!-- content goes here --> <form method="post" action="login2.php"> <label for="username">Username: </label><br /> <input type="text" name="username" id="username"><br /> <label for="password">Password: </label><br /> <input type="password" name="password" id="password"><br /> <input type="submit" name="submit" id="submit" value="Submit"> </form> <br /> <a href="register.php">Register</a> </div> <b class="sitebox"> <b class="sitebox5"></b> <b class="sitebox4"></b> <b class="sitebox3"></b> <b class="sitebox2"><b></b></b> <b class="sitebox1"><b></b></b></b> </div> </div> </body> </html> Then I get redirected to login2.php <?php // login2.php include("connection.php"); // Start a session. Session is explained below. session_start(); // Same checking stuff all over again. if(isset($_POST['submit'])) { if(empty($_POST['username']) || empty($_POST['password'])) { echo "Sorry, you have to fill in all forms"; exit; } // Create the variables again. $username = $_POST['username']; $password = $_POST['password']; // Encrypt the password again with the md5 hash. // This way the password is now the same as the password inside the database. $password = md5($password); // Store the SQL query inside a variable. // ONLY the username you have filled in is retrieved from the database. $query = "SELECT username,password FROM `users` WHERE username='$username'"; $result = mysql_query($query); if(!$result) { // Gives an error if the username given does not exist. // or if something else is wrong. echo "The query failed " . mysql_error(); } else { // Now create an object from the data you've retrieved. $row = mysql_fetch_object($result); // You've now created an object containing the data. // You can call data by using -> after $row. // For example now the password is checked if they're equal. if($row->password != $password) { echo "I am sorry, but the passwords are not equal."; exit; } // By storing data inside the $_SESSION superglobal, // you stay logged in until you close your browser. $_SESSION['username'] = $username; $_SESSION['sid'] = session_id(); // Make it more secure by storing the user's IP address. $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; // Now give the success message. // $_SESSION['username'] should print out your username. echo "Success! You are now logged in " . $_SESSION['username']; } } ?> Could I just include the login2.php context in a normal HTML site? Then comment out - echo "Success! You are now logged in " . $_SESSION['username']; and build from there. Would that be vaild or a mess? Thanks again. Edit: Sorry a bit to fast there. Just started up today that would be where I left of yesterday. This seems to do it. header( 'Location: view.html' );
Create an account or sign in to comment