Thanks for the tips, I tried the sessions part, but I'm getting an error, can anyone please help me with the code?
<?php
function auth(
$login = '',
$passwd = '',
$pass_file = 'words.txt'
) {
session_start();
global $PHP_SELF, $authdata;
$check = ! empty( $login );
if ( is_array( $authdata ) ) {
return true;
} elseif ( $check ) {
$fp = fopen( $pass_file, 'r' );
while ( !feof( $fp ) ) {
$line = trim( fgets( $fp, 1000 ) );
list( $l, $p ) = explode( ',', $line );
if ( ($l == $login) && ( $p == $passwd ) ) {
$authdata = array("login"=>$login);
session_register( 'authdata' );
fclose( $fp );
return true;
}
}
fclose( $fp );
unset( $authdata );
return false;
} else {
return false;
}
<?php
function loginform($error = false) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>my site</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body topmargin="0" leftmargin="0">
<div id="title">
<span class="text_header">xxxx</span><br />
</div>
<div id="main">
<div id="leftnav"><span class="text_nav_menu">about</span><br />
<a href="xxxx" class="link-menu">home</a><br />
<a href="xxxx" class="link-menu">resume</a><br />
<a href="xxxx" class="link-menu">contact</a><br />
<br />
<span class="text_nav_menu">my works</span><br />
<a href="xxx" class="link-menu" target="_blank">shearexcitement</a><br />
<a href="xxxx" class="link-menu" target="_blank">dariuswatts</a><br />
<a href="xxxx" class="link-menu" target="_blank">novaflow</a><br />
<a href="xxxx" class="link-menu" target="_blank">steve sciullo</a><br />
<br />
<span class="text_nav_menu">family</span><br />
<a href="xxxx" class="link-menu" target="_blank">mom</a><br />
<a href="xxx" class="link-menu" target="_blank">dad</a><br />
<a href="xxxx" class="link-menu" target="_blank">sister</a><br />
<br />
<span class="text_nav_menu">other</span><br />
<a href="xxxx" class="link-menu" target="_blank">arseblog</a><br />
<a href="xxxx" class="link-menu" target="_blank">herdreport</a><br />
</div>
<div id="blogcontent"><?php if($error) { ?>
The login information you provided was invalid.
Please log in again below:
<?php } //end of error check ?>
<FORM ACTION="<?php echo $PHP_SELF; ?>"
METHOD=POST>
Username: <INPUT TYPE="text" NAME="username"><BR>
Password: <INPUT TYPE="password" NAME="password"><BR>
<BR>
<INPUT TYPE="submit" VALUE="Log in">
</FORM>
<?php
} // end of function
if ( !auth($HTTP_POST_VARS['username'], $HTTP_POST_VARS['password' ) ) {
loginform( isset( $HTTP_POST_VARS['username'] ) );
}
echo "Welcome to the authorized site!";
?></div>
</div>
</body>
</html>
Also, if I want the user automatically redirected after successfully logging in, do I take out echo "Welcome to the authorized site!"; with header (Location: link);