This is the admin.php code.. I can show the login.php code too if needed. My question is what is in the index.php file that everything is leading into?
<html>
<?php
function userExists($file, $u)
{
$fp = fopen($file, "r");
$existe = 0;
while(!feof ($fp))
{
//$line = fgets($fp, 8000);
$line = fgets($fp, 1024);
$array = explode("|", $line);
$user = $array[0];
$pass = $array[1];
$url = $array[2];
if($user == $u){
$existe = existe + 1;
}
}
fclose($fp);
return $existe;
}
function frewrite($f, $r, $s)
{
$myFile = file($f);
foreach ($myFile as $row=>$data) { // $row is the line #, $data is the corresponding data to that line
//echo "$row: $data<br />\n"; // This will give you all rows + data in that file
}
//To edit a specific line:
$myFile[$r] = $s . "\n"; // Can be $myFile[0], $myFile[1], and so on
// To write:
$fp = fopen($f,'w');
fwrite($fp,implode('',$myFile));
fclose($fp);
}
function cutline($filename,$line_no) {
$strip_return=FALSE;
$data=file($filename);
$pipe=fopen($filename,'w');
$size=count($data);
if($line_no==-1)
{
$skip=$size-1;
}
else
{
$skip=$line_no-1;
}
for($line=0;$line<$size;$line++)
if($line!=$skip)
fputs($pipe,$data[$line]);
else
$strip_return=TRUE;
return $strip_return;
}
// END OF FUNCTIONS //
if ($_POST[user] && $_POST[pass] && $_POST[url] && $_POST[linha] == "")
{
if(userExists("ficheiro.txt", $_POST[user]) == 0)
{
$file=fopen("ficheiro.txt", "a");
fputs($file, "\n");
fputs($file, "$user|$pass|$url");
fclose($file);
print("<center><br>User added.<br>");
print ("<a href=\"index.php\"><p> Back </a></center>");
}
else
{
print "<center><br>There is a user with the corresponding username<br>";
print ("<a href=\"index.php\"><p> Back </a></center>");
}
}
elseif($_POST[action] == "doEdit") {
if($_POST[ed] != "")
{
$arg = $_POST[user] . "|" . $_POST[pass] . "|" . $_POST[url];
frewrite("ficheiro.txt", $_POST[linha], $arg);
print ("<center><a href=\"index.php\"><p> Back </a></center>");
}
elseif($_POST[dd] != ""){
cutline("ficheiro.txt", $_POST[linha]);
print ("<center><a href=\"index.php\"><p> Back </a></center>");
}
}
else{
?>
<form name="form2" method="post" action="index.php">
<input type="hidden" value="save" name="save">
<TABLE width=502 align=center border=1>
<TBODY>
<TR>
<TD width=137 ><STRONG> Username</STRONG></TD>
<TD width=362 ><INPUT name="user"></TD>
</TR>
<TR>
<TD><STRONG> Password</STRONG></TD>
<TD><INPUT type="password" name="pass"></TD>
</TR>
<TR>
<TD><STRONG> Url</STRONG></TD>
<TD><INPUT name="url"></TD>
</TR>
<TR>
<TD> </TD>
<TD><INPUT type=submit value=Save name=submit>
<input type="reset" value=Reset name="Reset"></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
<?php
if (file_exists("ficheiro.txt"))
{
$file=fopen("ficheiro.txt", "r");
print "<br><table width=\"55%\" align=center border=1>";
//if
$num = $num - 1;
while(!feof($file))
{
$linha = fgets($file, 1024);
$array = explode("|", $linha);
$user = $array[0];
$pass = $array[1];
$url = $array[2];
$num = $num + 1;
if($num == 0)
{
}
else {
if($user != "")
{
print "<form action=index.php method=post>";
print "<input type=hidden name=section value=user><input type=hidden name=action value=doEdit><input type=hidden name=linha value=$num>";
print "<tr><td width=\"137\"><input type=text name=user value=\"$user\"></td>
<td width=\"137\"><input type=text name=pass value=\"$pass\"></td>
<td><input type=text name=url value=\"$url\" size=\"50\"></td>";
print "<td width=\"35\"><input type=submit name=ed value=Edit></td>";
print "<td width=\"55\"><input type=submit name=dd value=Delete></td></tr>";
print "</form>";
}
}
}
print "</table>";
fclose($file);
print ("<br><center>number of users = $num <br></center>");
}
else {
print "The file doesn't exist!";
}
}
?>
<html>