Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Naprawa błędu w dodawaniu strony
Forum PHP.pl > Forum > Przedszkole
Maker5
Witam

Mam problem z moim panelem CMS.

Błąd polega na tym, że w trakcie dodawania nowej podstrony na stronie internetowej poprzez panel CMS

i kliknięcia zapisz pojawia się biała strona zamiast dodawać nową podstronę na stronę internetową.

Panel oparty o PHP Smarty.

Poniżej screeny pokazujące o co chodzi.

http://prnt.sc/og82qt
http://prnt.sc/og830p
http://prnt.sc/og859i
nospor
Jedyne co ci mozemy powiedziec na podstawie takiej masie informacji to: przejrzyj logi
Maker5
Cytat(nospor @ 17.07.2019, 12:51:31 ) *
Jedyne co ci mozemy powiedziec na podstawie takiej masie informacji to: przejrzyj logi


Jakie logi?
na serwerze czy w konsoli chrome?
nospor
A widzisz jakies interesujace info w logach consoli chrome?

Tak, na serwerze. Logi apache/nginx ewentualnie logi twojej aplikacji bo i ona moze jakies logi zapisywac
Maker5
Cytat(nospor @ 17.07.2019, 13:05:10 ) *
A widzisz jakies interesujace info w logach consoli chrome?

Tak, na serwerze. Logi apache/nginx ewentualnie logi twojej aplikacji bo i ona moze jakies logi zapisywac


ok mam, miałeś rację
oto treść pliku log
adres zmieniłem bo mi sugerowano

  1. /home/srw_strona/strona.pl/lib/classes/Session.class.php on line 29
  2. [17-Jul-2019 13:55:37 Europe/Warsaw] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function valid_text(), 3 passed in /home/srw_strona/strona.pl/admin/action/content.module.php on line 485 and at least 4 expected in /home/srw_strona/strona.pl/lib/MVC.function.php:460
  3. Stack trace:
  4. #0 /home/srw_strona/strona.pl/admin/action/content.module.php(485): valid_text('text', 'Jakas tresc<br ...', Object(Form))
  5. #1 /home/srw_strona/strona.pl/admin/index.php(109): contentMultiActionController->form_action()
  6. #2 /home/srw_strona/strona.pl/admin/index.php(162): MVC_Controller->Process()
  7. #3 {main}
  8. thrown in /home/srw_strona/strona.pl/lib/MVC.function.php on line 460
nospor
Cytat
Too few arguments to function valid_text(), 3 passed in /home/srw_strona/strona.pl/admin/action/content.module.php on line 485 and at least 4 expected
No i wszystko masz jak na dloni
Teraz idziesz do content.module.php linia 485 i poprawiasz smile.gif
Maker5
Cytat(nospor @ 17.07.2019, 14:40:12 ) *
No i wszystko masz jak na dloni
Teraz idziesz do content.module.php linia 485 i poprawiasz smile.gif


ale jak to poprawić, pomóż proszę bo nie wiem

załączam całą treść tego pliku content.module.php

linia 485 zaczyna się od formuły: $text = valid_text($field_2, get_http_request($field_2), $this->form);
jest na końcu poniżej

  1. public function form_action()
  2. {
  3. $field = "content_id";
  4. $content_id = get_http_request($field);
  5. $this->form->setValue($field, $content_id);
  6.  
  7. $field = "subaction";
  8. $subaction = get_http_request($field);
  9. $this->form->setValue($field, $subaction);
  10.  
  11. if($content_id != '' && eregi('^[0-9]+$', $content_id) && $this->content->check_id($content_id))
  12. {
  13. $field_1 = "title";
  14. $title = valid_input($field_1, get_http_request($field_1), $this->form, true);
  15.  
  16. $field_2 = "text";
  17. $text = valid_text($field_2, get_http_request($field_2), $this->form);
  18.  
  19. //$purifier = new HTMLPurifier();
  20. //$text = $purifier->purify($text);
nospor
No ja tez nie wiem.
Blad wyraznie mowi, ze funkcja valid_text() wymaga przynajmniej 4 parametrow, a w kodzie jest odpalana tylko z 3.

Nie aktualizowales ostatnio czegos tam w tej swojej appce?
Jak wyglada kod funkcji valid_text() ?
Maker5
Cytat(nospor @ 17.07.2019, 16:21:56 ) *
No ja tez nie wiem.
Blad wyraznie mowi, ze funkcja valid_text() wymaga przynajmniej 4 parametrow, a w kodzie jest odpalana tylko z 3.

Nie aktualizowales ostatnio czegos tam w tej swojej appce?
Jak wyglada kod funkcji valid_text() ?


tu jest chyba valid text

  1. function valid_text($field, $value, &$form, $required, $nl2br = false) {
  2. if (!$value || strlen($value = trim($value)) == 0) {
  3. if ($required == true)
  4. $form->setError($field, 'empty');
  5. else
  6. $value = '';
  7. } else {
  8. $value = stripslashes($value);
  9. if ($nl2br) {
  10. $value = nl2br($value);
  11. }
  12. $form->setValue($field, $value);
  13. $value = addslashes($value);
  14. }
  15. return $value;
  16. }
nospor
No to zmien
text = valid_text($field_2, get_http_request($field_2), $this->form);
na
text = valid_text($field_2, get_http_request($field_2), $this->form, true);
albo
text = valid_text($field_2, get_http_request($field_2), $this->form, false);

w zaleznosci czy wymagasz by pole bylo wymagane czy nie
Maker5
Cytat(nospor @ 17.07.2019, 16:30:51 ) *
No to zmien
text = valid_text($field_2, get_http_request($field_2), $this->form);
na
text = valid_text($field_2, get_http_request($field_2), $this->form, true);
albo
text = valid_text($field_2, get_http_request($field_2), $this->form, false);

w zaleznosci czy wymagasz by pole bylo wymagane czy nie


Zmieniłem na true i działa smile.gif dziękuję

sprawdzam jeszcze raz błędy w logach i mam kolejne dwa może wiesz czym spowodowane
poniżej szczegoły

  1. [17-Jul-2019 16:43:05 Europe/Warsaw] PHP Warning: session_regenerate_id(): Cannot regenerate session id - session is not active in /home/srw_strona/strona.pl/lib/classes/Session.class.php on line 29


zawartość session.class
  1. <?php
  2.  
  3. class Session
  4. {
  5. private static $instance;
  6.  
  7. private function __construct() {
  8. $this->startSession();
  9. }
  10.  
  11. public static function singleton() {
  12. if (!isset(self::$instance)) {
  13. $c = __CLASS__;
  14. self::$instance = new $c;
  15. }
  16. return self::$instance;
  17. }
  18.  
  19. public function __clone() {
  20. trigger_error('Klonowanie zabronione.', E_USER_ERROR);
  21. }
  22.  
  23. private function startSession() {
  24. $session_key = substr(md5(dirname(__FILE__)), 0, 8);
  25. session_name('SESSID' . $session_key);
  26.  
  27. ini_set('session.use_trans_sid', 0);
  28.  
  29.  
  30. }
  31. }
  32.  
nospor
Komunikat jest dosc wyrazny...

zmien kolejnosc o tutaj
session_regenerate_id();
session_start();
Maker5
Cytat(nospor @ 17.07.2019, 16:49:57 ) *
Komunikat jest dosc wyrazny...

zmien kolejnosc o tutaj
session_regenerate_id();
session_start();


dziękuję, nie pojawia się już w logach

i ostatni błąd jeśli mogę Cię prosić

  1. [17-Jul-2019 16:58:52 Europe/Warsaw] PHP Warning: preg_match(): Unknown modifier ']' in /home/srw_strona/strona.pl/lib/MVC.function.php on line 632


poniżej treść MVC.function.php - linia 632 zaczyna się od: return preg_match('/' . $pattern . '/', $value);

  1. if (!function_exists('eregi')) {
  2.  
  3. function eregi($pattern, $value, $output = false) {
  4. if (!$output) {
  5. return preg_match('/' . $pattern . '/', $value);
  6. } else {
  7. preg_match('/' . $pattern . '/', $value, $output);
  8. return $output;
  9. }
  10. }
  11.  
  12. }
nospor
Dobrzy by zobaczyc co zawiera zmienna $pattern. Da sie?
Maker5
Cytat(nospor @ 17.07.2019, 17:04:06 ) *
Dobrzy by zobaczyc co zawiera zmienna $pattern. Da sie?


jesli to w tym samym pliku to kod poniżej

  1. /**
  2.  * Method to sanitize incoming html.
  3.  * Take from cakephp (http://cakephp.org)
  4.  * Licensed under the MIT License
  5.  *
  6.  * @param unknown_type $string
  7.  * @param unknown_type $remove
  8.  * @return unknown
  9.  */
  10. function clean_html($string, $remove = false) {
  11. if ($remove) {
  12. $string = strip_tags($string);
  13. } else {
  14. $patterns = array("/\&/", "/%/", "/</", "/>/", '/"/', "/'/", "/\(/", "/\)/", "/\+/", "/-/");
  15. $replacements = array("&amp;", "%", "&lt;", "&gt;", "&quot;", "'", "(", ")", "+", "-");
  16. $string = preg_replace($patterns, $replacements, $string);
  17. }
  18. return $string;
  19. }
  20.  
  21. function seo_html($string) {
  22. $a = array('"', '\'');
  23. $b = array('', '');
  24. $string = str_replace($a, $b, $string);
  25. $string = preg_match("[^ĘÓĄŚŁŻŹĆŃęóąśłżźćńA-Za-z0-9]", " ", $string);
  26. $string = preg_replace("/\s+/", " ", $string);
  27. $string = preg_replace("/^\W+|\W+$/", "", $string);
  28. return $string;
  29. }
  30.  
  31. // ================================================================================
    =====================
  32. // internal function for utf8 decoding
  33. // thanks to Jamie Pratt for noticing that PHP's function is a little
  34. // screwy
  35. function my_utf8_decode($string) {
  36. return strtr($string, "?questionmark.gifquestionmark.gifquestionmark.gifĽľŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖŘŮÚŰÜÝßŕáâăäĺćçčéęëěíîďđńňóôőöřůúűüý˙", "SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
  37. }
  38.  
  39. // sanitize a string in prep for passing a single argument to system() (or similar)
  40. // input string, returns string stripped of special characters
  41. function sanitize_system_string($string) {
  42. $pattern = '/(;|\||`|>|<|&|^|"|' . "\n|\r|'" . '|{|}|[|]|\)|\()/i'; // no piping, passing possible environment variables ($),
  43. // seperate commands, nested execution, file redirection,
  44. // background processing, special commands (backspace, etc.), quotes
  45. // newlines, or some other special characters
  46. $string = preg_replace($pattern, '', $string);
  47. $string = '"' . preg_replace('/\$/', '\\\$', $string) . '"'; //make sure this is only interpretted as ONE argument
  48. return $string;
  49. }
  50.  
  51. // sanitize a string for SQL input (simple slash out quotes and slashes)
  52. // input string, returns string with slashed out quotes
  53. function sanitize_sql_string($string) {
  54. $pattern[0] = '/(\\\\)/';
  55. $pattern[1] = "/\"/";
  56. $pattern[2] = "/'/";
  57. $replacement[0] = '\\\\\\';
  58. $replacement[1] = '\"';
  59. $replacement[2] = "\\'";
  60. return preg_replace($pattern, $replacement, $string);
  61. }
  62.  
  63. // sanitize a string for HTML (make sure nothing gets interpretted!)
  64. function sanitize_html_string($string) {
  65. $pattern[0] = '/\&/';
  66. $pattern[1] = '/</';
  67. $pattern[2] = "/>/";
  68. $pattern[3] = '/\n/';
  69. $pattern[4] = '/"/';
  70. $pattern[5] = "/'/";
  71. $pattern[6] = "/%/";
  72. $pattern[7] = '/\(/';
  73. $pattern[8] = '/\)/';
  74. $pattern[9] = '/\+/';
  75. $pattern[10] = '/-/';
  76. $replacement[0] = '&amp;';
  77. $replacement[1] = '&lt;';
  78. $replacement[2] = '&gt;';
  79. $replacement[3] = '<br>';
  80. $replacement[4] = '&quot;';
  81. $replacement[5] = ''';
  82. $replacement[6] = '%';
  83. $replacement[7] = '(';
  84. $replacement[8] = ')';
  85. $replacement[9] = '+';
  86. $replacement[10] = '-';
  87. return preg_replace($pattern, $replacement, $string);
  88. }
  89.  
  90. // ================================================================================
    =====================
nospor
czyli nie da sie.... wink.gif

strzelam:
Zamien
return preg_match('/' . $pattern . '/', $value);
na
return preg_match($pattern, $value);
a jak to nie pomoze to zamien na
return preg_match('#' . $pattern . '#', $value);
Maker5
Cytat(nospor @ 17.07.2019, 17:09:23 ) *
czyli nie da sie.... wink.gif

strzelam:
Zamien
return preg_match('/' . $pattern . '/', $value);
na
return preg_match($pattern, $value);
a jak to nie pomoze to zamien na
return preg_match('#' . $pattern . '#', $value);


Wstawiłem ten drugi kod bo przy pierwszym pokazywało znów ten sam błąd z tą różnicą, że zamiast Unknown modifier ']' było Unknown modifier '('

ale teraz pojawia się inny w logu

  1. [17-Jul-2019 17:33:54 Europe/Warsaw] PHP Warning: array_pop() expects parameter 1 to be array, null given in /home/srw_strona/strona.pl/lib/classes/ScoutAgent.class.php on line 392


Zawartość ScoutAgent.class.php poniżej. Linia 392 zaczyna się od: $this->user_browser = array('name' => $browser[1], 'addon' => $addon, 'version' => array_pop($wersja), 'bot' => $browser[2]);

  1. /**
  2.   * Browser.
  3.   */
  4. private function _get_browser_addon()
  5. {
  6. while (list(,$addon) = each(parent::$tblb))
  7. {
  8.  
  9. /* if (eregi($addon[0], $this->user_agent, $wersja))
  10.   {
  11.   return $addon[1];
  12.   }
  13.   *
  14.   */
  15.  
  16. }
  17. return null;
  18. }
  19.  
  20. private function _get_browser()
  21. {
  22. while (list(,$browser) = each (parent::$tblc))
  23. {
  24. if (eregi($browser[0], $this->user_agent, $wersja))
  25. {
  26. $addon = ($browser[1] == 'Internet Explorer') ? $this->_get_browser_addon() : null;
  27. if (!isset($browser[2]))
  28. {
  29. $browser[2] = false;
  30. }
  31. $this->user_browser = array('name' => $browser[1], 'addon' => $addon, 'version' => array_pop($wersja), 'bot' => $browser[2]);
  32. return;
  33. }
  34. }
  35. $this->user_browser = false;
  36. }
  37.  
  38. public function is_browser()
  39. {
  40. if (!isset($this->user_browser))
  41. {
  42. $this->_get_browser();
  43. }
  44. return is_array($this->user_browser);
  45. }
  46.  
  47. public function browser($case = '')
  48. {
  49. if (!$this->is_browser())
  50. {
  51. return;
  52. }
  53.  
  54. switch (strtolower($case))
  55. {
  56. case 'name' : return $this->user_browser['name']; break;
  57. case 'addon' : return $this->user_browser['addon']; break;
  58. case 'version' : return $this->user_browser['version']; break;
  59. default :
  60. $out = $this->user_browser['name'].' '.$this->user_browser['version'];
  61. if (!empty($this->user_browser['addon']))
  62. {
  63. $out .= ' ('.$this->user_browser['addon'].')';
  64. }
  65. return $out;
  66. break;
  67. }
  68. }
  69.  
  70. /**
  71.   * System.
  72.   */
nospor
Przed ta linia daj

if ($wersja === null) {
$wersja = [];
}
Maker5
Cytat(nospor @ 17.07.2019, 17:54:02 ) *
Przed ta linia daj

if ($wersja === null) {
$wersja = [];
}


Dodałem to przed tą linią 392 i po kliknięciu dodaj stronę mam error 524 na cloudflare

  1. private function _get_browser()
  2. {
  3. while (list(,$browser) = each (parent::$tblc))
  4. {
  5. if (eregi($browser[0], $this->user_agent, $wersja))
  6. {
  7. $addon = ($browser[1] == 'Internet Explorer') ? $this->_get_browser_addon() : null;
  8. if (!isset($browser[2]))
  9. {
  10. $browser[2] = false;
  11. }
  12. if ($wersja === null) {
  13. $wersja = [];
  14. }
  15. $this->user_browser = array('name' => $browser[1], 'addon' => $addon, 'version' => array_pop($wersja), 'bot' => $browser[2]);
  16. return;
  17. }
  18. }
  19. $this->user_browser = false;
  20. }
nospor
A jaka masz wersje php?

Zamien
$wersja = [];
na
$wersja = array();
Maker5
Cytat(nospor @ 17.07.2019, 18:11:40 ) *
A jaka masz wersje php?

Zamien
$wersja = [];
na
$wersja = array();


Mam PHP 7.1 na hostingu

teraz działa smile.gif
nie ma błędu w logach smile.gif
dziękuję

a czy wiesz może dlaczego wczytywanie po kliknięciu "dodaj stronę" nie trwa powiedzmy do 5 sekund tylko z 30 sekund?
od czego to może zależeć?
nospor
Bo operacje jakies dziwne sa robione?
Patrzac jak kiepsko napisany jest ten skrypt nie zdziwilbym sie jakby byl totalnie nieoptymalny pod katem bazy rowniez
Maker5
Cytat(nospor @ 17.07.2019, 19:21:11 ) *
Bo operacje jakies dziwne sa robione?
Patrzac jak kiepsko napisany jest ten skrypt nie zdziwilbym sie jakby byl totalnie nieoptymalny pod katem bazy rowniez


chciałbyś zająć się tym odpłatnie?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.