Forum Moderators: coopster
<?php
session_start();
$u=$_POST[username_field];
$p=$_POST[password_field];
$_session["u"]=$u;
$_session["p"]=$p;
$array1 = file("data.txt");
$counter=0;
$username_counter=0;
$password_counter=0;
foreach ($array1 as $line) {
if ($counter/2==round($counter/2)) {
$username_array[$username_counter]=chop($line);
$username_counter++;
} else {
$password_array[$password_counter]=chop($line);
$password_counter++;
}
$counter++;
}
$match=0;
for ($x=0; $x<$username_counter;$x++) {
if (($u==$username_array[$x]) && ($p==$password_array[$x])) {
$match=1;
}
}
if ($match==0) {
print "<html>";
print "<head>";
print "<title>Login Page</title>";
print "<body>";
print "<center>";
print "<img src='images/secure.jpg'>";
print "<h1>Enter Username and Password Below</h1>";
print "<form name='form1' action='check_login.php' method='post'>";
print "<p>USERNAME:
<input type='text' size='20' name='username_field'></p>";
print "<p>PASSWORD:
<input type='text' size='10' name='password_field'></p>";
print "<input type='submit' value='LOGIN'>";
print "</form>";
print "</center>";
print "</body>";
print "</html>";
print "<center><b><font color='red'> **INVALID LOGIN** </font></b></center>";
} else {
header("Location:main.php");
}
?>
[edited by: jatar_k at 10:44 pm (utc) on Feb. 28, 2006]
[edit reason] trimmed code [/edit]
Here is what I have and I keep getting some parse error past lines at the end of the script for expecting $. I know it's probably simple but I am so tired of working on this, it's driving me insane. I don't even know if i'm on the right track.
session_start();
$np=$_POST[np];
$np2=$_POST[np2];
if(($np=="")¦¦($np2=="")){
include('chgpw.html');
print "New Password Field is blank. Please try again".$_SESSION["u"].".";
return false;
}else if (($np==$np2) && ($np!="")){
include('chgpw.html');
print "Passwords Do Not Match";
return false;
}else{
$u=$_SESSION["u"];
$p=$_SESSION["p"];
if (($np==$np2) && ($np=""))
{
for ($x=0; $x<count($u); $x++)
{
if ($u==$u[$x])
{
$p[$x]=$np;
$_SESSION["p"]=$p;
}
}
Header ("Location:confirmation.php");
}
$fp=fopen("data.txt","w+");
for ($x=0; $x<count($u); $x++)
{
fputs($fp,$u[$x]);
fputs($fp,"\n");
fputs($fp,$p["np"][$x]);
fputs($fp,"\n");
}
fclose($fp);
return false;
$np=$_POST[np];
$np2=$_POST[np2];
should be
$np=trim($_POST[np]);
$np2=trim($_POST[np2]);
since you are making your comparisons against empty string then you should trim them just to be sure they didn't enter only spaces
your 3 comparisons
1. if(($np=="") ¦¦ ($np2=="")){
2. } else if (($np==$np2) && ($np!="")) {
3. if (($np==$np2) && ($np="")) {
1. no problem
2. you don't need the second part of this at all because you have already tested to see if they are empty. The first part seems backwards, I think you meant to be testing for not equal, like so
} else if (($np!=$np2)) {
3. this comparison is actually inside your else and is not necessary as you won't reach your else if either of those are empty.
with those changes that gives me this
session_start();
$np=trim($_POST[np]);
$np2=trim($_POST[np2]);
if(($np=="") ¦¦ ($np2=="")){
include('chgpw.html');
print "New Password Field is blank. Please try again".$_SESSION["u"].".";
return false;
} else if (($np==$np2) && ($np!="")) {
include('chgpw.html');
print "Passwords Do Not Match";
return false;
} else {
$u=$_SESSION["u"];
$p=$_SESSION["p"];
for ($x=0; $x<count($u); $x++) {
if ($u==$u[$x]) {
$p[$x]=$np;
$_SESSION["p"]=$p;
}
header("Location:confirmation.php");
}
$fp=fopen("data.txt","w+");
for ($x=0; $x<count($u); $x++) {
fputs($fp,$u[$x]);
fputs($fp,"\n");
fputs($fp,$p["np"][$x]);
fputs($fp,"\n");
}
fclose($fp);
return false;
Also Header should be lower case ie. header. There is one more problem, you are missing a brace. it is inside your else, from there down there is a brace missing though I am not totally sure where it should be, my wild guess would be here
for ($x=0; $x<count($u); $x++) {
if ($u==$u[$x]) {
$p[$x]=$np;
$_SESSION["p"]=$p;
}
} <---- added right before your header call
# chgpw.php
session_start();
$np=$_POST[np];
$np2=$_POST[np2];
$u = $_SESSION["u"];
$p = $_SESSION["p"];
$u_list = $_SESSION["u_list"];
$p_list = $_SESSION["p_list"];
if (($np == $np2) && ($np!=""))
{
for ($x=0; $x<count($u_list); $x++)
{
if ($u==$u_list[$x])
{
$p_list[$x]=$np;
$_SESSION["p_list"]=$p_list;
}
}
header ("Location:confirmation.php");
}
else
{
print "<html>";
print "<head>";
print "<title>Change Password Page</title>";
print "<body>";
print "<center>";
print "<h1>Change Password</h1>";
print "<form name='form2' action='chgpw.php' method='post'>";
print "<p>NEW PASSWORD: <input type='text' size='20' name='np'></p>";
print "<p>RE-TYPE PASSWORD: <input type='text' size='20' name='np2'></p>";
print "<input type='submit' value='Submit'>";
print "<input type='button' value='Cancel' onClick='javascript:window.location='main.php'>";
print "</form>";
print "</center>";
print "</body>";
print "</html>";
print "<center><b><font color='red'> **PASSWORDS DO NOT MATCH** </font></b></center>";
}
-----------------------------------------------------
# confirmation.php
session_start();
$u_list = $_SESSION["u_list"];
$p_list = $_SESSION["p_list"];
print "<html>";
print "<head>";
print "<title>Confirmation Page</title>";
print "</head>";
print "<body>";
print "<center>";
print "<h1>Password Update - Successful</h1>";
print "<a href=\"main.php\">Main Page</a> ¦ <a
href=\"a4.html\">Log Out</a>";
$fp = fopen("data.txt", "w");
for ($x=0; $x<count($u_list); $x++)
{
fputs($fp,$u_list[$x]);
fputs($fp,"\n");
fputs($fp,$p_list[$x]);
fputs($fp,"\n");
}
fclose($fp);
print "</body>";
print "</html>";