Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dodanie tekstu do pliku w wybranym miejscu
AboutMe
post
Post #1





Grupa: Zarejestrowani
Postów: 261
Pomógł: 0
Dołączył: 24.02.2008

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


Witam,

Chciałbym dodać adresy IP z jednego pliku php do .htaccess. Znalazłem taki tutorial ale coś nie działa - http://www.learncomputer.com/php-insert-te...le-at-position/

  1. <?php
  2.  
  3. function insert_into_file($file_path, $insert_marker,
  4. $text, $after = true) {
  5. $contents = file_get_contents($file_path);
  6. $new_contents = preg_replace($insert_marker,
  7. ($after) ? '$0' . $text : $text . '$0', $contents);
  8. return file_put_contents($file_path, $new_contents);
  9. }
  10.  
  11.  
  12. $file_path = ".htaccess";
  13. $insert_marker = "<Files *.php>";
  14. $text = file_get_contents('/home/username/public_html/blog/logs/IPs.php', true);
  15.  
  16. $num_bytes = insert_into_file($file_path, $insert_marker, $text, true);
  17.  
  18. if ($num_bytes === false) {
  19. echo "Could not insert into file $file_path.";
  20. } else {
  21. echo "Insert successful!";
  22. }
  23. ?>


Chciałbym dodać zawartość IPs.php do .htaccess zaraz za <Files *.php>

Kod zwraca Insert successful! ale .htaccess jest nietknięty.

Nawet takie coś nie działa:

  1. function insert_into_file($file_path, $insert_marker,
  2. $text, $after = true) {
  3. $contents = file_get_contents($file_path);
  4. $new_contents = preg_replace($insert_marker,
  5. ($after) ? '$0' . $text : $text . '$0', $contents);
  6. return file_put_contents($file_path, $new_contents);
  7. }
  8.  
  9.  
  10. $file_path = ".htaccess";
  11. $insert_marker = "<Files *.php>";
  12. $text = "0000000";
  13.  
  14. $num_bytes = insert_into_file($file_path, $insert_marker, $text, true);
  15.  
  16. if ($num_bytes === false) {
  17. echo "Could not insert into file $file_path.";
  18. } else {
  19. echo "Insert successful!";
  20. }


Ten post edytował AboutMe 10.12.2013, 14:34:08
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 19.08.2025 - 07:01