Implementing a "nag" counter for javascript cookies [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
First and foremost, hello everyone. I know that I am new, and I apologize for the fact that I have no prior contributions.
That said, I am a student at Rasmussen. I have an assignment in my JavaScript class that requires that I create a "nag" counter that will alert the user on their fifth visit that they should register. Then I must do this for every fifth visit until the user A) Gets annoyed and stops using my website, or B) they register. At that time, I have to delete the cookie that holds the counter and the "nag" and replace it with a landing page that welcomes the user back to the website, displaying their registration credentials.
I know that this can be done, I have seen it numerous time. The problem that I am having is the fact that I am so new to JavaScript that feel like I am in way over my head. I have spent about 2 hours combing through my textbook, as well as Google, and I have not found any answers. I have asked my Instructor and fellow students for help but have yet to receive any. Te last time my instructor advised me, she said "Try Googling it."
I do not even know where to begin this assignment. I appreciate any help you may or may not be able to offer. I am not looking for a handout, or for anyone to do my assignment for me. I assure you I am in fact trying to learn something, but I feel this assignment it too much.

When a user loads the page, read the cookie to see if it exist. If it doesn't, set count = 1.
Once a user fills in the text boxes and clicks the register button, delete the nag counter cookie and replace it with cookies containing the user's name and e-mail address.
If they don't register, the next time they load the page, set count = 2.
On every 3rd visit, implement the nag. (use logic/control flow statements to achieve this)

Related

Detecting if the person viewing the website is the developer [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 1 year ago.
Improve this question
I have a view counter on my website that plots the time spent by a viewer on the site to a Thingspeak chart. I want it to not count my views. So it should detect me. I could maybe change the value of a boolean in Console but that isnt feasible. I thought about storing a cookie on my computer and the website would read it to see if it's me but then its crossite samesite stuff I don't understand. Then I thought about checking if the viewer's IP address is mine. Apparently you need server-side stuff for that and GitHub doesn't allow that. Any more ideas?
A really simple hacky solution without using IP checking / backend logic would be to set a localStorage value to something that shouldn't exist normally. With the site loaded, open your browser console and assign something, eg
localStorage.userIsIshanGoel = 'yes';
Then, in the script on your page, just check that property before running the code that increments the view count:
if (localStorage.userIsIshanGoel !== 'yes') {
incrementViewCount();
}
It's not foolproof - for example, someone could examine the source code of the page and set the property themselves, but if the view count is just for your personal informational use, that's quite unlikely to happen (and even then, that's only a single user).

Place Cookie to prevent re-visiting site [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a contest site, I want it to prevent people going on it when they have submitted the form on the page. Is this possibe?
Thanks
You could build system where users are required to enter their email address, and enter a verification code which is sent to them. But they would only be able to enter this verification code once. Therefore, the only way of cheating would be to use two separate email addresses (and they would have to have access to both).
Cookies would not be the best option for this as anyone could clear their cookies.
It's not necessarily possible to stop users requesting a page, however you can either redirect them to another page or show some kind of error message to them, to tell them that they can't resubmit.
Presuming you have some kind of user registration in place already (and are tying competition entries to those users with an ID) then all you would have to do is check for the existence of a competition entry in the database and then, if one is found, either force a redirect (likely in <script> tags) or replace the rendering of the page with the notice that you can't resubmit.

how to find user is logged in different browser or different system at a time using php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am implementing Online Examination System. If user is logged in different browsers at a time it should not be logged in. As well as Different system. Please help me how to restrict the user logging in different browsers. Please give any Example Code. So that i can understand easily. Thanks in Advance.
Try the following logic:
You can keep the username of logged in users in a list. Then each time a new login is made, check if the user is in that list. If it is, then redirect him to the error page else let hime proceed with examination. On logout you will remove the user from the list.

Detect fake user Agents? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to recover if someone is visiting my website using a fake user agent? If yes, can someone please tell me how can find out this information?
Thank you very much!
You can check the user agent from PHP like from this global variable $_SERVER['HTTP_USER_AGENT']. But if someone is using a fake user agent which claims to be something else* it's going to be difficult to spot.
This shouldn't really matter unless they are a hacker who is able to find some security weaknesses in your site and use those to do something nasty like access your database, delete all your data or download your users' credit card numbers.
The solution to the hacker problem is make sure your website is secure.
This is called 'spoofing' as #JAL mentions in his comment above.

How to make an event when there is a refresh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm making a web-quiz, there are the users logged in this game and they have to reply to a quiz with 3 alternatives, the problem comes when the user is a bit clever because if he does a refresh all the question change so the user can do this until he find the one that he knows, how can I put in my website (after an alert) wrong question?
example:
USA is in EU
UK is in Africa
France is in EU
If the users does a refresh, how can I show message such as alert("if you refresh is a game over") and save the answer as incorrect in the database?
I'd suggest assigning the question in PHP and storing which question you asked in a $_SESSION variable. That way when they refresh the page you can show them the same question until they answer it.
UPDATE
There is a caveat to this, if your user really is a smarty, they can delete their cookies and refresh the page, which would create a new session for them since session identifiers are saved as a cookie in PHP (by default).

Categories

Resources