PHP-файл для чтения и записи

0

поэтому я изучаю php и пытаюсь сделать счетчик хитов php для веб-страницы. Теперь я написал этот код в соответствии с моим пониманием. Проблема в том, что когда я запускаю программу в терминале, я получаю правильный ответ (вывод такой, как я ожидал). Когда я делаю эхо на странице html, это не работает. Вот код

<html>
<body>
<?php
    #open the file (assuming this file already exists with only 0 in it)
    $file = 'test.txt';
    $file = fopen($file,"r");
    $temp = fread($file, 1024);
    fclose($file);

    #save the number 0 (initial counter to $temp) and delete it)
    $file = 'test.txt';
    unlink($file);

    #open the file (this line just creates the file to write)
    $file = fopen("test.txt","w");
    fclose($file);

    #increase the counter by a number (10 for testing)
    $temp = (int)$temp + 10;
    $file=fopen("test.txt","w");
    fwrite($file,"$temp \n")
    fclose($file);
    #the file only contains a number ($temp - the final counter)

    echo "<h1>$temp<h1>";  #this outputs the correct counter in terminal but only        outputs 10 on html page. ????? 

?>
</body>
</html>
  • 0
    Вы обновили это да?
  • 0
    Да, он выводит 10 все время по какой-то причине. Хотя вывод терминала всегда корректен.
Показать ещё 4 комментария
Теги:
counter

1 ответ

0

Я думаю, что это проблема разрешения. Попробуйте изменить chmod/chown, например:

sudo chown coders:www-data test.txt
sudo chown 765 test.txt

Ещё вопросы

Сообщество Overcoder
Наверх
Меню