Jump to content

kicken

Gurus
  • Posts

    4,696
  • Joined

  • Last visited

  • Days Won

    178

Everything posted by kicken

  1. Set your old timestamp variable to null when the game is started/restarted. this.oldTimeStamp = null; Then in your game loop function, check if it's null and if so store the provided timestamp. if (this.oldTimeStamp===null){ this.oldTimeStamp=timeStamp; } This way your game always starts out at 0 for seconds passed. Currently, your first iteration when the page loads is essentially random as it depends on how long it takes for the browser to run the first game loop after starting the page.
  2. Try adding the indent option.
  3. Formatting values should always be a last-step operation. You want to structure your code so the prices remain as numbers and you can do whatever operations on them you need to do, then only format them right before you display them, for example directly in your template if possible. $price1 = 30; $price2 = 74.99; $bundle = $price1 + $price2; //...anything else //When everything is done and you're ready to display echo getMoneyUSD($price1); echo getMoneyUSD($price2); echo getMoneyUSD($price3); Also, you should know that floating point math can lead to issues due to lack of precision. A common way to avoid these issues is to work with your prices as integers (ie, number of cents) then convert them to decimals as part of the formatting process. Alternatively, you could find a library for dealing with currency values that handles such issues for you.
  4. If it works in the browser, but not in the command line then you probably have different configurations for the two environments. Your system may have multiple php.ini files, one that's used for web stuff and another used for CLI scripts. The output of the phpinfo() function will tell you where the INI file being parsed is. In the php.ini output you provided, you can see all the lines being with ; which means they are all commented out and not active. Try removing the leading ; from the oci lines to enable the extension. The effect should be immediate for CLI, but may need you to restart the webserver or fpm server for webpages.
  5. They need to go somewhere, unless you want to be manually entering them every time the system boots. The config files can have their permissions set so only root is able read them. If you're worried about someone else with root access reading the files, then your problem isn't "how to secure the environment variables?", it's "why does someone you don't trust have root access?". The other common solution is to not make them true environment variables at all and put them in a .env file in your application directory. Make that file readable only by the application's user and use something like symfony/dotenv to load it and access the variables using $_ENV. I do a mix of both in my applications which are based on the Symfony framework. I have SYMFONY_ENV=prod set as an environment variable in the server configuration to ensure it's running in production mode, then a .env.local file in the application directory that has all the secrets for the application.
  6. The FPM workers run in a clean environment via systemd. Setting clear_env in the pool configuration doesn't change that. You will need to either set the variables as part of the service definition in systemd or through the web server so they get passed to the fpm process. For example, if using apache add SetEnv YOUR_VAR the_value to your site configuration. Or set them in your pool configuration explicity with env[YOUR_VAR]=the_value
  7. kicken

    Greetings!

    Greetings, Laravel is popular, but I also find Symfony to be better. A lot of stuff (including Laravel) uses Symfony components under the hood so it's good to know it as well. Symfony uses Twig by default for it's templates. Twig has a lot of features, but at it's most basic level is fairly simple. You make one base template that defines your site structure then put {% block Blah '' %} anywhere that you want to be able to add content. Then you make a second file for your page and use {% extends 'base.html.twig' %} {% block Blah %}<p>The content</p>{% endblock %} To specify the content to be placed in said block. Keep up the learning and it'll all click eventually. PHP is a great and versatile language, and if you use it well and learn good design/architecture (which Symfony helps with I think) you can carry that knowledge over to other languages.
  8. This: str.append(fileInput.files.name, fileInput.files); Should be this: str.append(fileInput.name, fileInput.files[i]); You want the name of the form field to used, and the value needs to be a single file not the whole collection. Lastly, your input needs to have the name: name="file[]" So that PHP will accept it as an array.
  9. Pro tip: When asking for the output of var_export, we don't want an image of it. We want you to copy/paste it into a code block so we can copy/paste it into an editor and use it to help you debug the code. Posting an image is not useful and a great way to get people to ignore your thread. Second tip, if you want to work with individual words, you should probably be storing them individually in a their own table, not as a comma separated list in your links table. Then getting your unique list of words would be a simple select distinct query.
  10. For example, using systemd on Ubuntu server I have a small chat server script running as a service. It's run by systemd by creating a service file like this: [Unit] Description=PHP Chat Daemon [Service] Type=simple WorkingDirectory=/var/www/kicken/aoeex.com/content/chat/src/ ExecStart=/usr/bin/php phpchatd.php Restart=on-failure SyslogIdentifier=phpchatd [Install] WantedBy=default.target The script itself just sits in a loop waiting for connections. Your script would need to be setup to loop doing whatever it does as well.
  11. There are some ini settings that control how PHP rounds the precision of floating point numbers. There is a higher precision for serialization, so a quick and dirty way of seeing the "raw" numbers would be to serialize it. echo serialize('573.06'*100); shows d:57305.99999999999;
  12. This is not quite accurate. A leading slash indicates the root of the filesystem, not the root of the site. This is rarely what you want.
  13. You cannot return the result of your ajax request. The reason is because the function will have returned long before that result is available. Requests are done asynchronously (the first A in AJAX) which means your code doesn't wait for the request to complete, it keeps going wile the request runs. You get notified of the results via the callback functions (the success / error functions). Any processing you want to do with the results needs to be contained within those functions. Thus, you need to move the alert(result) code into your success function. If you don't want to literally move the code, you can move it by introducing a new callback function as a parameter. For example: function quickSubmit(form_data, sUrl, successCB){ $.ajax({ url: sUrl, method: "POST", data: form_data, contentType: false, cache: false, processData: false, success: function(data){ var result = JSON.parse(data); successCB(result); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); } quickSubmit([], '/', function(result){ alert(result); }); The same is true with any error handling, either put it directly into the error callback function, or create a new error callback parameter you can use. There are more modern and flexible ways of handling this like Promises and async/await but using them is a little more complicated. With async/await for example, you could write your function in a way that it seems to just return the results, but you need to set everything up properly first.
  14. The white under the curve is coming from the background set by #grve-content rather than the .grve-section class, so changing it wouldn't help. Whatever background the section would have gets clipped away by the .curved-bottom class, so the background you are seeing has to come from some parent element. If you only need the change for this page, set a rule that is limited to just it: #page-35941 { background-color: #dadada; } If you need it for several pages, create a new class you can apply to the page wrapper div.
  15. Your host is probably overriding it, possibly as a way to try and detect and shutdown spam accounts. You could contact your host and see if they have a solution.
  16. .closest would be better for buttons (maybe in general) since a child of the button (eg, <img>) might be the target of the click event.
  17. Yes, see Barand's example. The jQuery bits can be replaced with their plain DOM equivalents. window.addEventListener('DOMContentLoaded', function(){ document.querySelectorAll('.form-button').forEach(function(btn){ btn.addEventListener('click', function(e){ e.preventDefault(); alert('Button ' + e.currentTarget.value + ' clicked'); }); }); });
  18. You need to attach a click event to the buttons, not to the submit event on the form.
  19. You need to install the ODBC extension on your system. For example, with apt install php-odbc on something Debian based should do it.
  20. It would help if you posted the associated HTML and any other css needed to create a demo of your issue. Creating a fiddle showing the issue would be great for example as it makes it a lot easier for others see the issue and to try possible solutions.
  21. Assuming mysql, Your tables may be using the MyISAM engine which does not support transactions. You should be using InnoDB unless you have a specific reason not to.
  22. Typically mass imports are something that wouldn't be done via a web request. The task would be offloaded to a background task (through a cron job or task queue system) where you don't have to worry as much about timeouts. For example, for simple things I've typically inserted an import job into a table in the database with whatever information is needed for the import process. Then a second script run via a cron job on some interval checks that table for new import tasks and if one is found, performs the actual import task. This way the user isn't stuck with a loading page for however long the import takes, and the import task isn't subject to any timeouts other than PHP's max_execution_time settings (which is unlimited by default for CLI scripts).
  23. Your file has a invalid character in it that needs to be removed. Try deleting the line and re-typing it. Don't copy/paste or you'll copy/paste the character as well.
  24. The code to load your data seems to all be the same, so put it into a function and just call that function when you need to load the data. Your if(pageLink == "approverequest") { test seems pointless also since both branches do the same thing, so remove it. function loadProjectRequests(){ $("#requests-container").html( "<div class=\'col-sm-12 py-5\'><center><i class=\'fas fa-spinner fa-3x fa-spin mb-3 text-muted\'></i><br /></center></div>"); $("#requests-container").load("'.DIR.'admin/dashboard/requests", function(){ $("#project-requests").DataTable({ "order": [[0, "desc"]], "responsive": true, "lengthChange": true, "autoWidth": false, "pageLength": 25, "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]], "buttons": ["copy", "pdf", "print", "colvis"] }).buttons().container().appendTo('#project-requests_wrapper .col-md-6:eq(0)'); $("#project-requests_wrapper").children(":first").addClass("p-2"); $("#project-requests_wrapper").children(":first").next().next().addClass("p-2"); }); } $(document).ready(function(){ loadProjectRequests(); }); $(document).on("click", ".action-requests", function(e){ e.preventDefault(); var Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 5000 }); var pageLink = $(this).attr("href"); var requestId = $(this).attr("data-id"); $.post("admin/dashboard/queries/" + pageLink, { id: requestId }, function(data, status){ if (status === "success"){ Toast.fire({icon: "success", title: data}); loadProjectRequests(); } } ); });
  25. Line 113: <option value="<?=$PreviouseYear ?>" <?php if ($SE_YYYY_Entry == $PreviouseYear){ ?> SELECTED <?php }? > ><?=$PreviouseYear ?></option> Your closing PHP tag is malformed.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.