Forum Moderators: coopster

Message Too Old, No Replies

Sending 2 or more cookies in one page - problem!

         

ebemunk

6:14 pm on Sep 18, 2005 (gmt 0)

10+ Year Member



Hello. I am developing an image hosting site. You can upload multiple files at once. No registration is required in this site so I have found ways of tracking who uploaded which file. One of them is via cookies. Now the code is like this:
-------------
while ($i < $numberOfFiles) {
move_uploaded_file($_FILES["file" . $i]["tmp_name"], "img/" . $_FILES["file" . $i]["name"]);
$sql = mysql_query("INSERT INTO img (name, size, uploaderip, uploaderid, cat) VALUES ('$fRName', '$fSize', '$fUploaderIP', '$fUploaderID', '$fCat')");

if (!isset($_COOKIES["total"]))
setcookie("total", "0", time()+60*60*24*30*12*10);

$_COOKIE["total"]++;
setcookie("total", $_COOKIE["total"], time()+60*60*24*30*12*10);
setcookie("image[" . $_COOKIE["total"] . "]", $fRName, time()+60*60*24*30*12*10);
-----------------

now the problem here is I get "header already sent" error when trying to upload multiple files. One file is always OK but when I try multiple ones I get this error. Is there an easy way of doing this? THanks for help.

Kalashnikov

8:58 am on Sep 19, 2005 (gmt 0)

10+ Year Member



I think you'd better to use setcookie("total") only once.
$total = isset($_COOKIES["total"])? $_COOKIES["total"] : 0;
while ($i < $numberOfFiles) {
...
$total++;
}
setcookie("total", $total, time()+60*60*24*30*12*10);