Not tested thoroughly enough, obviously :) How about this?Code:<?php
define('DATABASE_FILE', 'database_fake.php');
define('SEPARATOR', ',');
define('LINEBREAK', "\n");
define('USERNAME', 0);
define('PASSWORD', 1);
define('EMAIL', 2);
define('COUNTRY', 3);
define('ZIP', 4);
function updateUser() {
$ret = 0;
$lines = array_unique(file(DATABASE_FILE));
$argv = func_get_args();
$conditions = array();
$changes = array();
for($i = 0; $i < count($argv) && $argv[$i] !== SEPARATOR; $i += 2)
$conditions[$argv[$i]] = $argv[$i + 1];
for(++$i; $i < count($argv); $i += 2)
$changes[$argv[$i]] = $argv[$i + 1];
for($i = 0; $i < count($lines); ++$i) {
$cline = explode(SEPARATOR, $lines[$i]);
$changeThisLine = true;
foreach($conditions as $k => $v)
if($cline[$k] != $v)
$changeThisLine = false;
if(!$changeThisLine) continue;
foreach($changes as $k => $v)
$cline[$k] = $v;
$lines[$i] = implode(SEPARATOR, $cline);
++$ret;
}
$f = fopen(DATABASE_FILE, 'w');
fwrite($f, str_replace(LINEBREAK . LINEBREAK, LINEBREAK, implode("\n", $lines)));
fclose($f);
return $ret;
}
?>
There are many different ways to accomplish this. For a start, that file is not referenced anywhere that's visible to the user, so it'd have to be one lucky spammer to stumble across the file (especially if you give it a slightly less obvious name).Quote:
And by the way if I remove the <?php exit()?> lines then anyone would be able to view the database(sure I could encrypt the password with md5 hash but what about the email addresses??They'd be a great source for spambots).
If that's not enough for you (and it shouldn't be, really) a simple solution is to move the file outside the web root.
