If you want to identify computers visiting your website, you will have to store the cookies of your website on the visiting computers.
Cookies: In simple words, HTTP cookies are small notes which store the user’s preferences about a particular website. For example, when a user shops online without logging in, he may put some items in the cart. Even after closing the browser and reloading the website, the items stored in the cart do not undergo any changes. This data of the user is stored as a cookie in the user’s computer itself. So, the next time the user visits the website, the data can be returned to the website server. Thus, the website is able to uniquely identify the computer.
For the more details about How cookies are used in a website?
Cookies working procedure:
- Whenever a computer visits your website, the server sends a cookie in a key-value format to the browser. Once the cookie is accepted by the browser, it is stored as a text record in the computer’s hardware.
- Now, when the computer visits your website, this cookie is retrieved from the computer and sent to the server. In this way, the server identifies the computer visiting the website and remembers the previous data exchange.
- Name-Value OR Key-Value: These are the only attribute pairs that are sent from the browser to the server when a computer visits a website repeatedly. Rest all attributes are used only by the browser to determine other properties.
- Domain and Path: The domain name of your website which controls the website’s authority over the internet. The path to the directory or web page that sets the cookie.
- Expires and Max-Age: Expires defines the time for which the cookie is stored in a browser, after which it is deleted. If this is blank, the cookie will expire when the visitor quits the browser.
Example: The following example demonstrates cookies, which stores cookies for 2 days and uses it to greet the user in their language. Upon running this code, the system asks you to enter your language”English/Spanish”. After entering this, you can run the code again and see that the system says “hello” to the user in the selected language.
Output:If “english” is selected, it gives alert message box , then the document message.
Hello Friend! You selected english! Now RUN it again.
A cookie does not guarantee that it will be able to identify the computer next time the user visits the website. This happens for three reasons.
- User has the complete authority to delete cookies and clear cache.
- Cookies are built to identify browsers. Next time, if the user visits your website through a different browser, the cookies will be stored separately on both browsers.
- Cookies will not work if the user has turned off the local cookie support in the browser.
To always identify the computer visiting your website, you will have to write a system application on the visiting computer.
- Web 1.0, Web 2.0 and Web 3.0 with their difference
- Classification of Computers
- How to Connect Two Computers with an Ethernet Cable?
- Minimum Manhattan distance covered by visiting every coordinates from a source to a final vertex
- How to identify server IP address in PHP ?
- Cookie Tracking and Stealing using Cross-Site Scripting
- If we delete cookies of a site, we can still logged in without logging again
- HTTP headers | Clear-Site-Data
- New Google Site Navigation Bar
- Difference between Web Scraping and Web Crawling
- Difference between Web Browser and Web Server
- How to choose Web Hosting Server and Web Domain ?
- Difference between Web Designer and Web Developer
- Differences between Web Services and Web API
- Progressive Web App - A Combination of Native and Web App
- 10 Web Development and Web Design Facts That You Should Know
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.