Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by iwato

  1. So, if I had written $result = array( 'rgb' => [], 'hex' => '' ); then I would not have had to rewrite the function. Is this correct? Roddy
  2. So, are you saying that $result['rgb'][$col] is being read as NULL[$col]? If so, what happened between PHP 5.3.8 and PHP 7.2 that changed $result['rgb'] from an element of an array to a string? Roddy
  3. BACKGROUND: The following newly created function works splendidly with PHP 5.3.8, but it fails nearly totally in PHP 7.2. Still there is no error message. The FUNCTION: function random_color($base = true, $type = true){ $result = array( 'rgb' => '', 'hex' => '' ); foreach( array('r', 'b', 'g') as $col){ $rand = mt_rand(0, 255); $result['rgb'][$col] = $rand; $dechex = dechex($rand); if(strlen($dechex) < 2){ $dechex = '0' . $dechex; } $result['hex'] .= $dechex; } if ($base == true) { if ($type == true) { return $result['rgb']; } else { return join(",", $result['rgb']); } } else { return strtoupper($result['hex']); } } QUESTION: What must I change to get it to work with PHP 7.2. HINT ONE: The function delivers well when the $base parameter is set to false. Otherwise, it returns only one of the three RGB colors no matter the value of $base or $type. HINT TWO: There is an error message after all. Simply, I was looking in the wrong place. [08-Aug-2019 18:04:40 UTC] PHP Warning: Illegal string offset 'r' in ..../includes/random_color.incl.php on line 15 [08-Aug-2019 18:04:40 UTC] PHP Warning: Illegal string offset 'b' in ..../includes/random_color.incl.php on line 15 [08-Aug-2019 18:04:40 UTC] PHP Warning: Illegal string offset 'g' in ..../includes/random_color.incl.php on line 15 ANSWER: function random_color($base = true, $type = true){ $result = array( 'rgb' => '', 'hex' => '' ); $keys = ['r', 'b', 'g']; foreach( $keys as $key => $value ){ $rand = mt_rand(0, 255); $result['rgb'][$value] = $rand; $dechex = dechex($rand); if(strlen($dechex) < 2){ $dechex = '0' . $dechex; } $result['hex'] .= $dechex; } if ($base == true) { if ($type == true) { return $result['rgb']; } else { return join(",", $result['rgb']); } } else { return strtoupper($result['hex']); } } NEW QUESTION: But why? Roddy
  4. It worked! As is often the case, I am heartily embarrassed. Sometimes I get so lost in the trees that I can no longer see the forest. The new resetForm() function: function resetForm() { $.ajax({ type: "POST", url: './php/captcha_reset.php', data: {dataRequest: 'requestInstance'}, statusCode: { 404: function() { alert( "Page not found" ); }}, success: function(jsonData) { jsonObj = JSON.parse(jsonData); captcha_sa = jsonObj.captcha_ra; $('#captcha_answer').val(''); $('#captcha_question').html(jsonObj.captcha_rq); $('#captcha_success').css('display', 'none'); $('#captcha_error').css('display', 'none'); } }); } Have a great day! Roddy
  5. That was my idea too, but I could not get it to work after two-and-one-half hours of experimentation. I have decided to provide all of the code with the exception of the modified PHP class, and add the following comments. The submitForm() function works well with each new page load. The resetForm() function works well with each button click. The submitForm() function fails to work after the resetForm() function has been activated. In effect, the function cannot match the word-number phrase with the number that is entered by the visitor and the error message results. Please skip to the dilemma for a quick technical understanding of the problem. The CODE //Create the first instance on page load and assign values. require_once("./php/classes/class.imageless_captcha.php"); $captcha_s = new ImagelessCaptcha(3, false, false); $captcha_sq = $captcha_s->formPhrase(); $captcha_sa = $captcha_s->getInt(); /*****************************************/ //Load the submitForm() and resetForm() functions. <script src='./javascript/imageless_captcha.js'></script> //The loaded functions. function submitForm(confirmCode) { var visitorConfirmation = confirmCode; if (visitorConfirmation == captcha_sa) { alert('Send search info for further processing.'); $('#captcha_success').css('display', 'block'); $('#captcha_error').css('display', 'none'); } else { $('#captcha_error').css('display', 'block'); $('#captcha_success').css('display', 'none'); } } function resetForm() { $.ajax({ type: "POST", url: './php/captcha_reset.php', data: {dataRequest: 'requestInstance'}, statusCode: { 404: function() { alert( "Page not found" ); }}, success: function(jsonData) { jsonObj = JSON.parse(jsonData); $('#captcha_answer').val(''); $('#captcha_question').html(jsonObj.captcha_rq); $('#captcha_success').css('display', 'none'); $('#captcha_error').css('display', 'none'); } }); } /*****************************************/ // Create a second instance of the ImagelessCaptcha class for the resetForm() function. <?php ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log'); ini_set('html_errors', 1); ini_set('display_errors', 0); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $captcha_reset = array(); if ($_POST['dataRequest']) { $dataRequest = filter_var($_POST['dataRequest'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); if ($dataRequest == 'requestInstance') { require_once('./classes/class.imageless_captcha.php'); $captcha_r = new ImagelessCaptcha(3, false, false); $captcha_reset['captcha_rq'] = $captcha_r->formPhrase(); $captcha_reset['captcha_ra'] = $captcha_r->getInt(); } } echo json_encode($captcha_reset); } ?> /******************************************/ A modified version of the ImagelessCaptcha class not included here. /*****************************************/ //Embed the success and error messages. <div id='captcha_error' style='display:none;'> <p>Error: The number that you entered was incorrect. Please try again.</p> </div><!-- end div#captcha_error --> <div id='captcha_success' style='display:none;'> <p>Congratulations! Your search request has been sent.</p> </div><!-- end div#captcha_success --> //Embed the captcha form <form> <div id='captcha_messaging'> <label id='captcha_question'></label><br> <input id='captcha_answer' type="text" value="" > </div><!-- end div#captcha_messaging --> <div id='captcha_buttons'> <input id='captcha_submit' type='button' style='width:100px;' value='submit'> <input id='captcha_reset' type='button' style='width:100px;' value='reset'> </div> </form> /*****************************************/ // Assign the PHP outcomes to their Javascript counterparts. <script> var captcha_sq = <?php echo "'" . $captcha_sq . "'"; ?>; var captcha_sa = Number(<?php echo $captcha_sa; ?>); $('#captcha_question').html(captcha_sq); </script> /*******************************************/ // Call the submitForm() and resetForm() functions <script> $(document).ready(function() { $('#captcha_submit').on('click', function() { confirmCode = Number($('#captcha_answer').val()); submitForm(confirmCode); }); $('#captcha_reset').on('click', function() { resetForm(); }); }); </script> The DILEMMA Replace the value of the captcha_sa variable in the submitForm() function with the value of newly generated captcha_ra variable generated by the resetForm() function. function submitForm(confirmCode) { var visitorConfirmation = confirmCode; if (visitorConfirmation == captcha_sa) {...} ... } } Please advise. Roddy
  6. BACKGROUND: I have a javascript document that is dynamically loaded when a certain condition is met. In this document there are two functions: the first function is called submitForm(), and the second is called resetForm(). Each of these functions is triggered separately by a different button on the same HTML webpage. Both functions rely on the same PHP class, but each relies on data created by a different instance containing different data. The first instance is created at run time and is ultimately read into the submitForm() function. The second instance is created at the visitor's discretion via an AJAX call that is made when the resetForm() function is triggered. The success function of the AJAX call made by the resetForm() function generates a value needed by the submitForm() function when it is run for a second time after the resetForm() function has already been called once. QUESTION: How do I get the resetForm() function to return a value generated by its AJAX call's success function in a manner that it can be used by the submitForm() function? Sorry, no code, as the whole process is even a little more complicated than what has just been explained.. Please advise. Roddy
  7. Have a great week end! Roddy
  8. QUESTION THREE: By way of confirmation, may I use the same require_once() function as many times and places as I like during the same browser session with good confidence that it will be included/required only once? Roddy
  9. A Ha! A "hitherto by me yet to be employed" technique is now on the table. Please do not run away for the weekend just yet. QUESTION ONE: Are you suggesting that the .js file extension is just a file accounting convenience and has no effect on whether Javascript is run? QUESTION TWO: Are there any additional security problems associated with setting the server to run javascript (.js) files with PHP? Roddy
  10. I do not have what you are suggesting, but you have answered my question with regard to multiple include statements. I do have one more question before you disappear for the week end. Will PHP used to create new instances of the same previously called PHP class and to assign values to Javascript variables be properly read when the Javascript file is loaded. Or, must the assignment be achieved via AJAX or some other, hitherto by me yet to be employed, technique? Roddy
  11. Not exactly! I have modified a class that someone else designed for a very different environment. Right now I am concerned about where to include the class, so that its inclusion does not become redundant on the one hand, and so that it is always and everywhere available on the other. There is a three step process involved. 1) Load the HTML mainpage. 2) Call a Javascript document that loads any of three search <div>s on the mainpage into the mainpage's main <div>. 3) Call a another Javascript document that captures the search data and sends it off to a PHP file via AJAX for processing on the mainpage. Roddy
  12. BACKGROUND: I have three search forms included in three different <div>s on the Grammar Captive main page. Initially all three of the forms are hidden. When a visitor selects one of the three forms, the javascript file associated with the main page performs a test in order to ascertain whether previous search data associated with the form is recoverable. if so, two of two additional javascript files is loaded. If not, only one of them. This latter file is crucial to both scenarios. GOAL: As I strongly suspect that my database is being spammed with repeated entries of the same search data, I am in the process of creating an imageless captcha in order to frustrate the spammer, but not the visitor. DILEMMA: The code that creates the Captcha is a simply written PHP class called ImagelessCaptcha, and I need to create a new instance of the class each time a new search is made. CONSIDERED SCENARIO: Load the PHP class when the mainpage opens and create a new instance from the loaded class each time the one of the pair of aforementioned javascript files is called. QUESTION: My concern is where and how I should call the new instance. Is this a problem for AJAX? Any suggestions? Roddy
  13. $.each(jsonData, function(key, object) { var searchItem = {}; var nakedArabic = []; var agex = new RegExp(/[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\uFDF0-\uFDFD]/g); $.each(object, function(name, value) { if (name === 'searchKeyword') { if (agex.test(value)) { nakedArabic = value.match(agex); searchItem.target = '\u2067' + nakedArabic.join('') + '\u2069'; } else { searchItem.target = value; } } if (name === 'searchCategory') { searchItem.category = value; } if (name === 'searchResultsCount') { searchItem.count = value; } }); searchItems.push(searchItem); }); Alas, I have resolved this problem: listItem: Array [ "subject-verb pairs", 157 ] listItem: Array [ "subject-verb agreement", 157 ] listItem: Array [ "&quotperson and number&quot", 471 ] listItem: Array [ "person", 157 ] listItem: Array [ "´person and number", 157 ] listItem: Array [ "person and happiness", 314 ] listItem: Array [ "´person and happiness", 157 ] listItem: Array [ 141, "الدواعيمنفكرةقرامركابتِف" ] with the following text wrapper: searchItem.target = '\u2067' + nakedArabic.join('') + '\u2069'; After three weeks of study that led me down many new paths I was finally able to identify the source of the problem. The numbers that followed the Arabic text were being read as part of the Arabic text. In order to prevent this from occurring it was necessary to isolate the Arabic text. As I was dealing with Javascript, it was not possible to achieve this with normal HTML mark-up. Whereupon, I discovered something called Unicode Controls. I wish the discovery had been as simple as the solution, but in the end I have issued from the inquiry victorious and far better informed about Unicode, Javascript, and Bidirectional Text. Roddy
  14. OK. I get it.! The properties value and enumerable are property descriptors. They define the nature of the property getFoo. Thanks! Roddy
  15. jsonLikeObj.getFoo.value( ); BACKGROUND: Consider the following object var jsonLikeObj = Object.create( {}, {getFoo: { value: function() { return this.foo = 1; }, enumerable: false } } ); DISCUSSION: Now I could more easily understand the following that does not work, than what does work. What Does Not Work jsonLikeObj.getFoo.value(); What Does Work jsonLikeObj.getFoo(); QUESTION: What is going on? Roddy
  16. Dsonesuk, I have awarded you the cup for a helpful accident on your part. Please compare the following two pieces of code. The first fails; the second works: FAILED CODE $('body, html').animate({scrollTop: $('#your_tutor').offset().top},800); WORKING CODE $('body, html').animate({scrollTop: $('#your_tutor').offset().top},800,function(){ $('html,body').clearQueue(); }); There appears to be some sort of jQuery bubbling going on. Roddy
  17. So, all of the selectors currently identified by $('body, html') should read $('body'). Is this correct? Roddy
  18. Actually, no. The problem occurs with the page to which the link on the page for which the above CSS code appears. I believe that I have inadvertently misled you. Please focus on the following statement and ignore the code that I provided in my previous entry. It is from a different page and a different problem. Roddy
  19. Hi, Dsonesuk. I have checked all of the relevant HTML and CSS documents that go into producing the mainpage with the GC Tutor insert. In no case does the word overflow appear. No, I have not change my browser's setting. In any case, the issue is not browser sensitive. I would like to bring your attention to the CSS used to format the tutor.grammarcaptive.com subdomain index page. /* CSS Stylesheet for GC Tutor ** Date of Creation: Sunday, 21 October 2018 ** Author: Roddy A. Stegemann */ body, html { height: 100%; background-color: #666; color: #ccc; } .parallax { background-image: url('../../_images/la_brume.png'); height: 100%; background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; } h1, h2, h3, p { text-align: center; } @media only screen and (max-device-width: 1366px) { .parallax { background-attachment: scroll; } } #contact_div { display: -webkit-flex; display: flex; flex-direction: column; justify-content: start; margin-bottom: 1em; } .contact_item { display: -webkit-flex; display: flex; flex-direction: row; justify-content: space-between; flex-wrap: wrap; } .contact_info { padding: 0 1em; text-align:right; color: #ccc; } .contact_data { padding: 0 1em; } a:link {text-decoration: none;color: #ccc; border:none} a:visited {text-decoration: none;color: #D4AF37;} a:hover {text-decoration: none;color: #fff;font-weight: 800;} a:active {text-decoration: none;color: #D4AF37;} Do you find anything strange or unusual here? Roddy
  20. OK. I have now got the scrolling to work in all instances. The only thing that remains to be solved is the stuttering. There are six different conditions that must be met: Computer Browser 1) Load the insert directly from the mainpage by clicking on GC Tutor in the navigation bar. 2) Load the insert directly from the subdomain tutor.grammarcaptive.com 3) Load the insert from the subdomain, load other inserts, and then load the insert GC Tutor, as if the page were loaded directly from the mainpage. Smart Phone 1) Load the insert directly from the mainpage by clicking on GC Tutor in the navigation bar. 2) Load the insert directly from the subdomain tutor.grammarcaptive.com 3) Load the insert from the subdomain, load other inserts, and then load the insert GC Tutor, as if the page were loaded directly from the mainpage. Note: In the end, the functionality does not work on both the smartphone and the computer unless the dual specification is employed in all cases -- namely, $('body, html'). Unfortunately, in all cases the stuttering persists. Roddy
  21. Using the HTML tag alone corrects the problem on my iPhone, but does not correct the stuttering effect in my computer's browser window. Roddy
  22. $('body, html').animate({scrollTop: $('#your_tutor').offset().top},800); Oh, I see what you mean. This technique is used throughout my site, and I have not had trouble with it. What would you suggest that I target? The loaded gctutor_div, the main div in which the gctutor.div resides, the html div, or the body div. I am referring only to the affected offset at this point. Roddy
  23. If the second scroll mechanism is not included in the original .load( ) function, the second scroll fails completely. The entire .load( ) function is provided below. What you see is slightly different from what appears on the original page of this thread. Neither the original, nor the modified position alters either originally stated outcome. MODIFIED CODE $("#main").load("gctutor_filler.html #gctutor_div", function() { $(".hidden_tr").hide(); $("#hidden_handyman").hide(); $(".seeMore").css({"font-family": "'Bradley Hand', 'cursive'", "font-size": "1.2em", "color": "#fadb9d"}); $("span.windowAdjust").css({"font-family" : "'Bradley Hand', cursive", "color":"#fadb9d", "font-size" : "1.2em"}); $('body, html').animate({scrollTop: $('#main').offset().top},800); $(".seeMore").mouseenter(function() { $(this).css({"cursor": "pointer", "color":"#fff"}); }) .mouseout(function() { $(this).css({"cursor":"none","color":"#fadb9d"}); }); $("span.windowAdjust").mouseenter(function() { $(this).css({"cursor": "pointer", "color":"#fff"}); }) .mouseout(function() { $(this).css({"cursor":"none","color":"#fadb9d"}); }); $("span.windowAdjust").mouseenter(function() { $(this).css({"cursor": "pointer", "color":"#fff"}); }) .click(function() { $('body, html').animate({scrollTop: $("nav #availability").offset().top}, 800); }) .mouseup(function() { $(this).css({"cursor":"none","color":"#fadb9d"}); }); $(".seeMore").mouseenter(function() { $(this).css({"cursor": "pointer", "color":"#fff"}) }) .click(function() { var hm_content = $("#handyman").html(); $(".hidden_tr").slideToggle(function() { $("#replace_td").html(hm_content); $('body, html').animate({scrollTop: $('#your_tutor').offset().top},800); }); }) .mouseup(function() { $(this).css("color" , "#fadb9d"); $("#replace_td").css({"font-family": "inherit", "color": "#fff"}); }); }); Roddy
  24. Although it is true that two scrolls do take place within the same .load() function, they are very separate actions. The first scroll is automatically triggered when the div is loaded, the second takes place at the visitor's discretion and occurs only after the div is loaded, if it occurs at all. Roddy
  25. Have you tried your mobile device. There it simply fails. Yes, if one waits in a non-mobile environment the problem does correct itself, but internet users are generally impatient and demand perfection. Too many quirks will chase them away. Are you suggesting another way to expose a hidden div that does not use Javascript? Roddy p.s. If I ever build another site, or have someone overall the current site, things will be done very differently. Developing is a learning experience on the one hand, and a business enterprise on the other. One must balance between the two. Neither can I afford an overall, nor can I afford the time to build another site at this moment.
  • Create New...