Backend increment counter PHP or javascript [duplicate] - javascript

This question already has answers here:
PHP Increment a counting variable in a text file
(5 answers)
Closed 6 years ago.
After researching I am not really sure which is a matching solution for my project. I want a serverside number incr. counter, that daily resets.
Every website vistor should see the same number of the counter. Is there
a PHP script or javascript meaningful? Can I store the daily counts in a txt.-file without using a database like MySql?

It would be helpful if you specified a little further what you are trying to achieve. What is the counter counting? number of visits? number of clicks?
You could store this in a text file. I wouldn'r recommend it thought, it will be bulky and you will run into trouble when several updates takes place simultaneously. A better solution if you want an easy and file-based database, check SQLite.

Related

How do I clear chrome.storage.sync for testing my extension? [duplicate]

This question already has answers here:
How to clear chrome.storage.local and chrome.storage.sync?
(4 answers)
Closed 1 year ago.
I am making a little logic game as a chrome extension, to add a high score I wanted to use chrome.storage.sync. I want to only create a variable if it doesn't exist (the first time someone is opening the extension). To test if what I wrote works I have to clear all data for myself, how could I do that? (the documentation speaks senior developer and I am not one of those so I don't understand)
https://developer.chrome.com/docs/extensions/reference/storage/
chrome.storage.local.clear()
thats will Removes all items from storage.
you can also remove some keys and not all items by,
chrome.storage.local.get((data) => {
// here you get all data and you can decide which keys to delete,
// in this case im deleting all keys explicitly
chrome.storage.local.remove(Object.keys(data), resolve)
})

How to update one property of nested maps in firebase firestore [duplicate]

This question already has answers here:
How to update elements in arrays of maps in Firestore?
(1 answer)
How to update() an array of maps-objects on Firestore in Angular or Angularfirestore?
(1 answer)
How can I update map data that's in a array in firebase? (Flutter)
(2 answers)
Closed 2 years ago.
I am doing a side project where I am trying to learn some about firestore, so i am making a hybrid shopping list/work hour tracker web app, here I want to ask about storing work hours in firestore.
Here i have the picture showing the structure i have come up with for my work hour tracker.
Above you can see a date that is an object, or map as firestore calls it, which is a day. This day contains all the start and end dates of the work day(the user can toggle when he/she is working or not). This way i can display a overall time worked by calculating the difference between "date_start" of the first object and the "date_end" of the last object, in the work_hours array. Also allowing me to visualise a more detailed list with the work hours.
Furthermore if the last object in the array does not have an "date_end" i can know for sure that i have to show a timer that is counting from the last "date_start" to now.
I have tried in multiple ways to update this array, but none worked like i intended them to, the closest i got was with upload method and specifying the path to "work_hours" map. but still i have to re-upload the whole modified array, which does not seem optimal to me... Sure it is not a huge operation, but it is a waste of resources in my mind, which is not necessary.
Now my question is: How to update just the "work_hours" array in this document field without needing to upload it again?
Alternatively: Any suggestions that are able to achieve a similar result or even better result, without needing to re-upload the whole map to the document, which have a different structure from mine.

Simplest way to store this to do list data even after browser closed? [duplicate]

This question already has answers here:
How to store objects in HTML5 localStorage/sessionStorage
(24 answers)
Storing JSON data in browser memory
(3 answers)
Closed 4 years ago.
I want to make a web-based TO-DO list exactly like the one on the W3schools link below, however when I close the browser all the inputs and edit disappear and it reverts back to the original. Is it possible to easily store the values (if not I will quickly delete this Q)? What code can I add to make it save the data (perhaps localstorage?) each time or would I have to set up a php/mySql? No authentication required, whatever is the most straightforward way to do it.
The exact code is below. I prefer to host locally for simplicty but if necessary web based hosting server is also fine with me.
To Do List Example from W3 Schools
You can use Javascript LocalStorage to save data on browser close, only if it is being loaded on a domain that is accessed via HTTP.
Though, you can use a server-side database, such as mySQL to store data.

Time ticks on client [duplicate]

This question already has answers here:
The best way to synchronize client-side javascript clock with server date
(8 answers)
Closed 9 years ago.
I have a scenario in which I have to show ticking time to the user of a post. The post will come with is original DateTime string from server then the values will be calculated on client to find the difference of the time elapsed. The issue is that client time can't be relied upon. So the decision is that to retrieve the server current time and find the difference between the client and server and add that difference to the client date and then add the difference to the client time before calcuating the time elapsed.. however I don't know how to find the difference in javascript and add it client date variable.. Can someone talk on this scenario and codify it.. I am not sure whether I am doing right or is there alternative to it?
So I come up with the solution now.. as I mentioned to use the variable to store the server current time and update that variable after each specific interval in setinterval. This variable is going to work as our client side clock and compare the post time with it.. the issue with client clock is that it can't be trusted..

Passing javascript variables between pages [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Persist javascript variables across pages?
how to exchange variables between two html pages
I am working on creating a "quiz" that allows users to answer questions, then passes their answer and current score to the next page for the next question. I used this article and was able to get the user's answer to pass through to the next window:
http://www.htmlgoodies.com/beyond/javascript/article.php/3471111/A-Quick-Tutorial-on-JavaScript-Variable-Passing.htm
The issue is that this passes the information through a form. Once I receive the score on the second page, I need to increment the score if the answer was correct. I can't figure out how to pass a javascript variable with an html form.
I feel like this should be a relatively easy fix, I'm just stumped.
Any thoughts or advice would be much appreciated!
xoxo
There are two obvious ways to maintain state in the browser without requiring that the server remember it between pages:
Cookies
localStorage
The latter is trivial to implement, but is only available in HTML5.
Note that neither is intended to be secure - a determined page hacker could set either to whatever value they wish.
You can submit a form using get method <form method="get" then use javascript to parse params in url. Reference here:

Categories

Resources