Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Ochrona plików mp3 przed cache'm Opery
zorkmyst
post 23.08.2010, 00:20:11
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.08.2010

Ostrzeżenie: (0%)
-----


Witam, zacznę o tego że jestem noobem php wstydnis.gif więc proszę o wyrozumiałość. Pracuję nad stronką, na której użytkownicy mogą odtwarzać pliki mp3. Wykorzystuje w tym celu dewplayer'a z playlistą w xml. Dla ochrony przed bezpośrednim pobieraniem pliki mp3 znajdują się poza public_html serwera. Odwołanie do pliku realizuje za pomocą prostego skryptu php:

  1. <?php
  2.  
  3. $file = "/katalog/poza/public_html/".$_GET["file"].'.mp3';
  4. $fh = fopen($file,"rb");
  5. $mm_type = "application/octet-stream";
  6. while (!feof($fh))
  7. {
  8. header("Cache-Control: no-store, must-revalidate");
  9. header("Pragma: hack");
  10. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  11. header("Content-Type: " . $mm_type);
  12. header('Content-Length: ' . filesize($file));
  13. print(fread($fh, filesize($file)));
  14. }
  15.  
  16. fclose($fh);
  17.  
  18. ?>


plik wywoływany jest na zasadzie skrypt.php?file=nazwapliku. Żeby uprzedzić - do skryptu też nie da się odwołać bezpośrednio. Generalnie wszystko śmiga, problem jest z cache Opery. Za każdym razem kiedy plik jest otwierany w playerze Opera wrzuca go do swojego Cache. Czy istnieje jakiś sposób zabezpieczenia się przed takim zachowaniem Opery? Czy można w jakiś sposób poza headerami ustawić czas wygaśnięcia pliku w cache?

Pozdrawiam
Go to the top of the page
+Quote Post
flashdev
post 23.08.2010, 00:28:44
Post #2





Grupa: Zarejestrowani
Postów: 812
Pomógł: 117
Dołączył: 2.12.2008

Ostrzeżenie: (10%)
X----


Co prawda nie jest to zbyt eleganckie rozwiązanie, ale przynajmniej tymczasowo możesz 'wyłączyć' cache na jeden z poniższych sposobów.

  1. $file = "/katalog/poza/public_html/".$_GET["file"].'.mp3' . '?rnd=' . mt_rand();
  2. header('Location: '.$file);


  1. $file = "/katalog/poza/public_html/".$_GET["file"].'.mp3';
  2. $file .= '?md5=" . md5_file($file);
  3. header('Location: '.$file);


--------------------
Go to the top of the page
+Quote Post
piotr94
post 23.08.2010, 08:17:27
Post #3





Grupa: Zarejestrowani
Postów: 331
Pomógł: 30
Dołączył: 11.11.2008
Skąd: Kraków

Ostrzeżenie: (0%)
-----


a http://php.net/manual/en/function.header.php i Example #2


--------------------
http://www.piotr94.net21.pl/ - wykonanie stron i serwisów internetowych
Jeśli moje wypowiedzi były dla Ciebie pomocne, kliknij "Pomógł" i odwdzięcz się ;)
Go to the top of the page
+Quote Post
zorkmyst
post 23.08.2010, 14:44:48
Post #4





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.08.2010

Ostrzeżenie: (0%)
-----


Dziękuję za szybką odpowiedź. Nie wiem czy dobrze zaimplementowałem, ale dla rnd:

  1. <?php
  2. $file = "/katalog/poza/public-html/".$_GET["file"].'.mp3' . '?rnd=' . mt_rand();
  3. $fh = fopen($file,"rb");
  4. $mm_type = "application/octet-stream";
  5. while (!feof($fh))
  6. {
  7. header('Location: '.$file);
  8. header("Cache-Control: no-store, no-cache, must-revalidate");
  9. header("Pragma: hack");
  10. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  11. header("Content-Type: " . $mm_type);
  12. header('Content-Length: ' . filesize($file));
  13. print(fread($fh, filesize($file)));
  14. }
  15. fclose($fh);
  16. ?>


serwer generalnie szaleje dostaje w logach:

[error] [client xxx.xxx.xxx.xxx] PHP Warning: fread() expects parameter 1 to be resource, boolean given in skrypt-1.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: feof() expects parameter 1 to be resource, boolean given in skrypt-1.php on line 5
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/demo.mp3?rnd=1511147903 in skrypt-1.php on line 12
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/demo.mp3?rnd=1511147903 in skrypt-1.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: fread() expects parameter 1 to be resource, boolean given in skrypt-1.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: feof() expects parameter 1 to be resource, boolean given in skrypt-1.php on line 5
itd...

dla md5

  1. <?php
  2. $file = "/katalog/poza/public_html/".$_GET["file"].'.mp3';
  3. $file .= '?md5=" . md5_file($file);$fh = fopen($file,"rb");
  4. $mm_type = "application/octet-stream";
  5. while (!feof($fh))
  6. {
  7. header('Location: '.$file);
  8. header("Cache-Control: no-store, no-cache, must-revalidate");
  9. header("Pragma: hack");
  10. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  11. header("Content-Type: " . $mm_type);
  12. header('Content-Length: ' . filesize($file));
  13. print(fread($fh, filesize($file)));
  14. }
  15. fclose($fh);
  16. ?>


w logach:

[error] [client xxx.xxx.xxx.xxx] PHP Parse error: syntax error, unexpected T_STRING in skrypt-2.php on line 7

Testowałem już header'y. Niestety z Operą nic nie działa.

Pozdrawiam
Go to the top of the page
+Quote Post
vermis
post 23.08.2010, 15:00:50
Post #5





Grupa: Zarejestrowani
Postów: 279
Pomógł: 56
Dołączył: 3.06.2010
Skąd: Tarnowskie Góry

Ostrzeżenie: (0%)
-----


  1. #
  2. $file .= '?md5=" . md5_file($file);$fh = fopen($file,"rb");

otwierasz apostrofem a zamykasz cudzysłowem.


--------------------
Go to the top of the page
+Quote Post
zorkmyst
post 23.08.2010, 15:29:06
Post #6





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.08.2010

Ostrzeżenie: (0%)
-----


Dzięki, mój błąd. Wprowadziłem zmianę i dostaję w logach:

[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/.mp3?md5= in skrypt-2.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: fread() expects parameter 1 to be resource, boolean given in skrypt-2.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: feof() expects parameter 1 to be resource, boolean given in skrypt-2.php on line 5
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/.mp3?md5= in skrypt-2.php on line 12
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/.mp3?md5= in skrypt-2.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: fread() expects parameter 1 to be resource, boolean given in skrypt-2.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: feof() expects parameter 1 to be resource, boolean given in skrypt-2.php on line 5
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/.mp3?md5= in skrypt-2.php on line 12
[error] [client xxx.xxx.xxx.xxx] PHP Warning: filesize(): stat failed for /katalog/poza/public_html/.mp3?md5= in skrypt-2.php on line 13
[error] [client xxx.xxx.xxx.xxx] PHP Warning: fread() expects parameter 1 to be resource, boolean given in skrypt-2.php on line 13

Skrypt wywołuje na zasadzie skrypt.php?file=demosong

Pozdarawiam
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.07.2025 - 06:10