viv Posted August 17, 2008 Share Posted August 17, 2008 Hey & Thanks for stopping in. If anyone could help me get this straightened out I would really appreciate it. I am a php newbie trying to set up a simple login via this tutorial: http://www.trap17.com/index.php/php-simple-login-tutorial_t7887.html When I put it up I receive the following errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/arcadias/public_html/login.php:5) in /home/arcadias/public_html/login.php on line 6 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/arcadias/public_html/login.php:5) in /home/arcadias/public_html/login.php on line 6 Warning: main(dbConfig.php) [function.main]: failed to open stream: No such file or directory in /home/arcadias/public_html/login.php on line 8 Warning: main(dbConfig.php) [function.main]: failed to open stream: No such file or directory in /home/arcadias/public_html/login.php on line 8 Warning: main() [function.include]: Failed opening 'dbConfig.php' for inclusion (include_path='/usr/lib/php:.:/usr/php4/lib/php:/usr/local/php4/lib/php') in /home/arcadias/public_html/login.php on line 8 Here is my code: <html> <head></head> <body> <?php session_start(); // dBase file include "dbConfig.php"; if ($_GET["op"] == "login") { if (!$_POST["userName"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `Members` " ."WHERE `userName`='".$_POST["userName"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["userName"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"userName\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/120017-php-login-sessions-issue/ Share on other sites More sharing options...
Fadion Posted August 17, 2008 Share Posted August 17, 2008 Put the session_start() in the very beginning of your code, even before the html tags: <?php session_start(); ?> <html> <body> <!-- rest of the code --> Link to comment https://forums.phpfreaks.com/topic/120017-php-login-sessions-issue/#findComment-618255 Share on other sites More sharing options...
viv Posted August 17, 2008 Author Share Posted August 17, 2008 Thanks so much for the help! Link to comment https://forums.phpfreaks.com/topic/120017-php-login-sessions-issue/#findComment-618258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.