Hey, could you please tell me what is wrong with my login script. I
just started learning php.
CODE:
login.php
<?
session_start() ;
header("Cache-Control: private");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Please Login</title>
</head>
<body>
<form action="script. php" method="get">
<table summary="Login Table">
<tr>
<td>username: </td>
<td><input type="text" name="login"></td>
</tr>
<tr>
<td>password: </td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td><input type="submit" value="login"></td>
</tr>
</table>
</body>
</html>
script.php
<?
session_start() ; //start session
header("Cache-Control: private");
if (!$_GET["login"] || !$_GET["login"])
{
print<<<END
I'm sorry, but your not logged in or there was an error logging you
in. Please<br>
<a href="login.php ">go here</a> to try again. Sorry for any
inconvienince.
END;
}
else
{
//register session variable: 'login' and 'pass'
$_SESSION["login"] = $_GET["login"];
$_SESSION["pass"] = $_GET["pass"];
if ($_SESSION["login"] == "Koolyio" && $_SESSION["pass"] == "wow")
//if credentials are true
{
$_SESSION["access"] = true;
}
else
{
$_SESSION["access"] = false;
}
}
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<script language="JavaS cript" type="text/javascript">
<!--
location.href = "main.php";
//-->
</script>
<noscript>Sorry , but your browser doesn't support JavaScript, ergo you
cannot
login</noscript></html>
END;
}
else
{
print<<<END;
I'm sorry, but one or more of the credentials you supplied were
incorrect. Please
try to login again <a href="login.php ">here</a>.
END;
?>
logout.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
$_SESSION = array();
session_destroy ();
print("<a href=/"login.php/">log in</a>
}
?>
main.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<head>
<title>Member s Only</title>
</head>
<body>
You have succesfully logged in. You can now <a href="logout.ph p">log
out</a>
</body>
</html>
END;
}
else
{
print<<<END
Sorry, You have not logged in correctly. Please try again <a
href="login.php ">here</a>.
END;
}
?>
just started learning php.
CODE:
login.php
<?
session_start() ;
header("Cache-Control: private");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Please Login</title>
</head>
<body>
<form action="script. php" method="get">
<table summary="Login Table">
<tr>
<td>username: </td>
<td><input type="text" name="login"></td>
</tr>
<tr>
<td>password: </td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td><input type="submit" value="login"></td>
</tr>
</table>
</body>
</html>
script.php
<?
session_start() ; //start session
header("Cache-Control: private");
if (!$_GET["login"] || !$_GET["login"])
{
print<<<END
I'm sorry, but your not logged in or there was an error logging you
in. Please<br>
<a href="login.php ">go here</a> to try again. Sorry for any
inconvienince.
END;
}
else
{
//register session variable: 'login' and 'pass'
$_SESSION["login"] = $_GET["login"];
$_SESSION["pass"] = $_GET["pass"];
if ($_SESSION["login"] == "Koolyio" && $_SESSION["pass"] == "wow")
//if credentials are true
{
$_SESSION["access"] = true;
}
else
{
$_SESSION["access"] = false;
}
}
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<script language="JavaS cript" type="text/javascript">
<!--
location.href = "main.php";
//-->
</script>
<noscript>Sorry , but your browser doesn't support JavaScript, ergo you
cannot
login</noscript></html>
END;
}
else
{
print<<<END;
I'm sorry, but one or more of the credentials you supplied were
incorrect. Please
try to login again <a href="login.php ">here</a>.
END;
?>
logout.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
$_SESSION = array();
session_destroy ();
print("<a href=/"login.php/">log in</a>
}
?>
main.php
<?
session_start() ; //start session
header("Cache-Control: private");
if ($_SESSION["access"] == true)
{
print<<<END
<html>
<head>
<title>Member s Only</title>
</head>
<body>
You have succesfully logged in. You can now <a href="logout.ph p">log
out</a>
</body>
</html>
END;
}
else
{
print<<<END
Sorry, You have not logged in correctly. Please try again <a
href="login.php ">here</a>.
END;
}
?>
Comment