Jump to content

PHP Login Sessions issue


viv

Recommended Posts

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

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.