0

I am using the following script: http://fofwebdesign.co.uk/template/_testing/click-count/

And I keep receiving the following error: Notice: Undefined offset: 1 in .../public_html/counter.php on line 18

<?php 
$file = 'counter.txt'; // path to text file that stores counts
$fh = fopen($file, 'r+');
$id = $_REQUEST['id']; // posted from page
$lines = '';
while(!feof($fh)){
    $line = explode('||', fgets($fh));
    $item = trim($line[0]);
    $num = trim($line[1]);
    if(!empty($item)){
        if($item == $id){
            $num++; // increment count by 1
            echo $num;
            }
        $lines .= "$item||$num\r\n";
        }
    } 
file_put_contents($file, $lines);
fclose($fh);

?>  

I am not sure what is causing it as I made no modifications to the script. Is it related to my hosting?

Help will be highly appreciated.

Thank you very much!

Mor
  • 55
  • 7
  • That means there is no `$line[1]` element, possibly because your `explode()` string doesn't contain more than one element. What is in `$fh` at the point you get the error message? – droopsnoot Oct 30 '20 at 13:02
  • Thank you for the reply, i have checked other answers but none of them are relevant. – Mor Oct 30 '20 at 13:33
  • @droopsnoot On my index file there is: – Mor Oct 30 '20 at 13:34
  • @droopsnoot and – Mor Oct 30 '20 at 13:35
  • @droopsnoot but on every button there is: Clicked times. – Mor Oct 30 '20 at 13:35
  • Don't put multiple lines of code in comments - you can't format them. If they are relevant, edit your question and put them in there where you can make them readable. – droopsnoot Oct 30 '20 at 18:04
  • None of that seems to go anywhere near the error that you were asking about. As I asked earlier, what is in `$fh` when your code runs? – droopsnoot Oct 30 '20 at 18:06

0 Answers0