0

I want to make download counter in my site with this script :

 <?php
$counter = 'apk/counter.txt'; // text file to store download count - create manually and put a 0 (zero) in it to begin the count
$download = 'http://site.my/apk/file.apk'; // the link to your download file
$number = file_get_contents($counter); // read count file
$number++; // increment count by 1
$fh = fopen($counter, 'w'); // open count file for writing
fwrite($fh, $number); // write new count to count file
fclose($fh); // close count file
header('Location: $download'); // get download
?> 

But the result say

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/download.php:1) in /home/user/public_html/download.php on line 9

How to fix it?

pah
  • 4,700
  • 6
  • 28
  • 37
Reza Fahmi
  • 270
  • 4
  • 11

1 Answers1

3

It means that content has already been sent to the browser, so you can't send any more headers. It could be caused by the space preceeding your opening <?php tag.

Will Vousden
  • 32,488
  • 9
  • 84
  • 95