Don't use session_register() unless you're running a PHP version older than 4.2.0. All session data should be stored in the $_SESSION array, not in "registered" global variables.
That said, you have several major problems that we need to address. The first is that your form input fields are not wrapped within a <form> element, so they are technically invalid. Where are you submitting the data, and using what method (get or post)?
Also, your simple code assumes that the global variables $lname and $lpass are copied into global scope from either the session data or the submitted form data. This is bad style, since it's a forced naming conflict.
Before PHP 4.2.0, this technique was thought to be extremely clever, but the cleverness fades once you take into account that naming conflicts tend to open security holes in your application.
For more info, I strongly suggest you read my old FAQ on the subject. There are several relevant links to the PHP manual discussing this issue.
http://p2p.wrox.com/archive/beginnin...2002-11/17.asp
That all said, your error messages are complaining that some output was already sent to the client before your call to session_start(). Typically, this is because you have some whitespace outside of your <?php tag. This whitespace is interpreted as HTML output by PHP, so when it encounters this, it will send the default HTTP headers to the client.
Remove all whitespace and HTML from before your first <?php tag.
Your script should look like this:
-----------------------------------------------------
<?php // Note: I'm not using the short tag. You shouldn't either!
session_start();
?>
<html>
<head><title>Login Page</title></head>
<body>
<form method="post" action="go.php">
Name: <input type="text" name="lname" /><br />
Password: <input type="text" name="lpass" /><br />
<input type="submit" value="Go" name="submit" />
</form>
</body>
</html>
-----------------------------------------------------
-----------------------------------------------------
<?php
session_start();
if (isset($_POST['lname']) && isset($_POST['lpass']))
{
$_SESSION['lname'] = $_POST['lname'];
$_SESSION['lpass'] = $_POST['lpass'];
}
if (!isset($_SESSION['lname']))
{
echo "You're not logged in.\n";
}
else
{
echo $_SESSION['lname'] . "\n";
echo $_SESSION['lpass'] . "\n";
}
?>
-----------------------------------------------------
Hope this helps! Also, read the manual for more tutorials and examples:
http://www.php.net/session
Take care,
Nik
http://www.bigaction.org/