PHP Code

<?
$login = '';
if( $txtlogin )
{
if($txtlogin == 'arvind')
{
if ($argc > 0 )
{
$redirect = $argv[0];
}
else
{
$redirect = '';
}

if($redirect != '')
{
print "redirect ";
}
else
{
//print "DSADSADSAD";
session_start();
$login = $txtlogin;
session_register('login');
header("Location : main.html");
// exit;
}
}
}
?>

<head>
<title>Login</title>
</head>
<body>
<form name="frmlogin" method="post" action="<? echo $PHP_SELF ?>">
Login name : <input type="text" name="txtlogin">
Password : <input type="password" name="txtpassword">
<input type="submit" name="btsubmit" value="Login">
</form>
</body>

Warning: Undefined variable: txtlogin in login.php on line 3

Y does this warning appear ? And how can i avoid it from appearing.

    Your getting that error because $txtlogin doesn't exist at the point you are doing comparisons on it.

    I don't know what php option controls getting this error or not because I've noticed I get this type of error on one of my servers and not on another.

    You could always change error handling or the error reporting level to see if you can get rid of it, or you could use @ to hide the error, if/when it occurs.

    Having said that, a better coding practice would to never being doing tests on a variable that may not exist.

    Try starting out with a test for isset($txtlogin) and only if its set would you do the latter comparisons.

    Scott A. Hammond, Sr., CEO
    Prima Internet, Inc.

      Write a Reply...