📜 ⬆️ ⬇️

PHP warning / notice messages in the JS console + secret button

When it is necessary to edit the code on the working site, there is a need to handle possible errors, and do it imperceptibly to the user. First, you need to define your own function for handling php errors.

Summarize one of the possible designs:
Create a condition under which the script will know that I / you are its creator (or try to be). To do this, we use cookies, for example, the presence of a cookie with the name "time6288456272719" = "234567u8". An ordinary user / interested person will not understand what it means. Now in php we check this cookie, and if it exists, we write the following construction:

<?php /* * ,  cookie    . */ if ( isset($_COOKIE['time6288456272719']) && $_COOKIE['time6288456272719'] == "234567u8") { set_error_handler('ereporting'); // ereporting -      set_exception_handler('ereporting'); } else { error_reporting(0); ini_set('display_errors', 'off'); ini_set('display_startup_errors', 'off'); } /* * $ereporing array =     */ $ereporing = array(); function ereporting($errno, $errstr, $errfile, $errline) { $r = ' | '; // '|' - ,     global $ereporting; //   ,     $ereporting[] = $errno . $r . $errstr . $r . $errfile . $r . $errline; //    return true; } /* * ,       . * ,    'ROOT',       * DOCUMENT_ROOT'a. * *        ,    . */ function ereportingRead() { global $ereporting; //     ?><script type="text/javascript">try{<?php //   js   try if ( is_array($ereporting) ) { foreach($ereporting as $line) { ?>console.warn("<?php echo str_replace(ROOT,'',$line);?>");<?php //     } } else { ?>console.log('ok')<?php //       } ?>}catch(e){}</script><?php } 


Creating this record itself, you can implement on js by clicking for example, on the icon of the copyright in the footer. The code could be:
')
 /* *   ,  : <span id="d73ghd"></span> *   -  *   ,    *   jQuery  jQuery cookie ( .) */ $('#d73ghd').click( function() { var c = 'time6288456272719'; return (!$.cookie(c)) ? $.cookie(c,'234567u8',{expires:1,path:'/'}) : $.cookie(c,null); } ); 


Naturally, you can do it through administrator authorization, but the idea exists.

My first blog entry may be a bit trite and / or unprofessional, comment.

Thanks for attention.

Source: https://habr.com/ru/post/140369/


All Articles