hi everybody!
i'm sweating over my very first php script ... and so far g things are going reasonably well ... here's the quick scenario ...
- the entire thing is going to be some sort of survey
- user comes to index.php and chooses one of two options (radio buttons)
- submitting the form calls my "setup.php" script (see script below)
- the script reads the "user_id.txt" file (contains only a number - for the first user, this would be "0")
- the script increments this number by "1" and replaces the old id in "user_id.txt"
- the script then creates a new text file with the composite file name "user_"."$newid".".txt" and writes a bunch of info
the script itself works perfectly fine (i'm very surprised) but for the reading of "$previd" (line 6) and the calculation of "$newid" (line 7) ... for some reason, i'm quite stuck since the result is always "1", no matter how often i run the script ... (argh.)
any helping hand you guys could lend to help me fix this would be very, very much appreciated!! 😃
cheers,
kubik
PHP:
[FONT=courier new]
1 : <?php
2 : //part 1 - open "user_id.txt" file, read old id, calculate new id, replace old id with new one, close
3 : //
4 : $filename = "user_id.txt";
5 : $handle = fopen ($filename, "w+");
6 : $previd = fread ($handle, filesize($filename));
7 : $newid = $previd + 1;
8 : fwrite ($handle, $newid);
9 : fclose ($handle);
10: //
11: //part 2 - create unique user id file, write info
12: //
13: $filename1 = "user$newid.txt";
14: $handle1 = fopen ("user$newid.txt", "a+");
15: $fcontentd = date ("d.m.Y, H:i:s");
16: $fcontentip = $REMOTE_ADDR;
17: $fcontentb = $HTTP_USER_AGENT;
18: fwrite ($handle1, "$fcontentd"."\n"."\n"."$fcontentip"."\n"."\n"."$fcontentb"."\n"."\n");
19: //
20: //part 3 - if (on previous page) the user chose "opt2" goto "setup_b.php", else (opt1) goto "survey01.php"
21: // document option and close file
22: //
23: if ($option == 2) {
24: fwrite ($handle1, "survey option 2 - personalized"."\n"."\n");
25: header ("Location: setup_b.php");
26: } else {
27: fwrite ($handle1, "survey option 1 - automated"."\n"."\n");
28: header ("Location: survey01.php");
29: }
30: fclose ($handle1);
31: ?>[/FONT]