Count Form Submissions on PHP Site [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to implement a counter on a site I am building, so every time someone submits a form on the site, the counter increases for anyone who visits the site. For example, the number will start at 0 and every time someone submits the form, the count will increase for anyone who visits the site.
I know how to manipulate the number via JS/jQuery when the form submission button is clicked. My question is about how to update the number on the site for anyone who visits the site.
The site is currently a static PHP site without a database associated with it.

oh i get it now..
you can do it with a file.
1) create a file called "counter.txt", put it next to your web page put the number zero in the file.
2) get the current count with php: $counter = file_get_contents("counter.txt");
3) add one to the counter file_put_contents("counter.txt", $counter+1);
// put this wherever you want to do your counting
$counter = file_get_contents("counter.txt");
file_put_contents("counter.txt", $counter+1);
echo "You are the $counter person to view this page..";

Related

How to let users upload or change the uploaded images in one page, and display it in another page? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
How to let user upload image in one page, and then display it in another page? User can change the image and it'll be changed also in the other page. Also, I'm talking about using php / js / jquery / mysqli anything that's most efficient. (I'm just a beginner in this field so it'll be appreciated if you use some simple language :))
Edit: Yes I said that I'm a beginner, but that doesn't mean I don't know a thing about coding. Also, I saw a few solutions from youtube & other stackoverflows questions, but all of them is about either uploading and displaying in the same page or not being able to change the image.
Format the image into Base64 string
store it in local-storage
In another page get it from local-storage and assign to the id or class.
Suggesting the link that already have answered for
How to save an image to localStorage and display it on the next page?

How can I register how many times a 'user' visits a website? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'd like parts of my website to be non-visible to the user if the user has accessed the website more than a certain number of times. The NY Times website has similar functionality.
I use react & firebase.
I did think about getting a user's IP address but my understanding is that measures geography, not necessarily a device.
P.S. If this question's unsuitable for SO, would you mind suggesting another forum, if you know of one, where it'd be more suitable?
You can use js and the local storage of the client browser to do that the easy way (but it can be easily cheated on by cleaning history).
Just copy/past that in an .html file and it will work if you refresh more then 4 times :
<script>
var dontDisplayPage = false;
if (localStorage.getItem('numberViews') === null){
localStorage.setItem('numberViews', 1);
} else {
localStorage.setItem('numberViews', parseInt(localStorage.getItem('numberViews'), 10) + 1);
}
if(parseInt(localStorage.getItem('numberViews'), 10)>4){
dontDisplayPage = true;
}
if(dontDisplayPage) alert('too many views !');
</script>
Then looking at dontDisplayPage you know if you must display the page, here dontDisplayPage is true if page has been seen more 4 times.
Based on that you can hide the div containing the article for exemple and display a message.

Display HTML Element Across Multiple Pages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I currently have a timer set up on an “admin” page with JavaScript and I want to display that same live clock on the homepage of my website. How can I do this? It’s basically two input fields that display number values. One displays minutes and one displays seconds. The values are updated using buttons which are found on the admin page. What I’m trying to do is display the current time that the clock is showing on the admin page on a separate page. Is there a simple way to do this?
You could store the value of the timer server side and just query it each second to see at what time it currently is. You could also use socket.IO to have real time access to the server timer.
It's impossible. website is connectionless.
You can't push any event to other client page
without client behavior(like button click..)

Increment the counter of each category using javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am using php for my application and i have 180 vendors registered on my app,each vendor has a unique id which is stored in database.I have to implement a counter that each time a user clicks on a view details button of a particular vendor the counter of that particular vendor is incremented and is shown on the vendor portal of that vendor . I don't have an exact idea how to approach this problem so I can show that how many times the user has clicked the view details button of that particular vendor.Can anyone guide me ?
Since you are using php there is no hard and fast rule to update counter on database. You should create a method that update counter on your database and use ajax to call that function using javascript or when user clicks on view detail then I think the page loads from new url. If this is the case then before rendering the page you should include call a function to increment the counter associated with the vendor in your database.
Create a table in the DB with vendor id and a counter. Each time a user clicks on a view details button of a particular vendor increment the counter, i.e update the counter in the DB using ajax call. Hope you are familiar to call a ajax function and update the DB.

Prevent back button exploits? PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've built a simple game using Javascript and PHP. Once the user hits the target score, they are allowed to add their name to a highscore mysql database. I'm using PHP POST to get their score and add it to mysql.
After someone get's a highscore and enters their name, it resets the score variable back to zero and redirects them back to the main game page with header('location'). If they hit the back button once, all is good, it shows their score is zero since I reset the variables. However if they hit the back button twice it brings up their high score and they can enter their name again and flood the highscore database with their name.
Anyway to prevent this?
You need to check for at least one identifying feature of the user and check if they have submitted a score before serving up the form. There are various ways you can do this, each with their own weaknesses, so it's best to mix and match, however some off the top of my head include:
Checking that a person with the same IP and user-agent string hasn't submitted a highscore in the last x minutes (though this may prevent some legit scores from being submitted - think a school / office using same browser and having same ip)
Putting a tracking cookie on arrival with an identifying user id. Then checking that user id hasn't submitted a score in the last x minutes. (e.g. start a PHP session if you want)
Adding a cookie to the browser after score submit, then checking for this cookie before serving up the form (yes, it can be easily worked around by deleting the cookie). Alternatively You could set a value in the session)

Categories