• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer
EDUCBA

EDUCBA

MENUMENU
  • Resources
        • Java Tutorials

          • Cheat Sheet Java
          • Cheat Sheet Python
          • C# vs Js
        • Java Tutorials
        • Python Tutorials

          • Angular 5 vs Angular 4
          • Careers in Python
          • Kali Linux vs Ubuntu
        • Python Tutorials
        • Top Differences

          • Cheat Sheet JavaScript
          • Python Interview Questions
          • Cloud Computing or Virtualization
        • Top Differences
        • Others

          • Resources (A-Z)
          • Top Interview Question
          • Programming Languages
          • Web Development Tools
          • HTML CSS Tutorial
          • Technology Basics
          • Technology Careers
          • View All
  • Free Courses
  • All Courses
        • Certification Courses

          Software Development Course 2
        • All in One Bundle

          All-in-One-Software-Development-Bundle
        • Become a Python Developer

          Python-Certification-Training
        • Others

          • Java Course
          • Become a Selenium Automation Tester
          • Become an IoT Developer
          • Ruby on Rails Course
          • Angular JS Certification Training
          • View All
  • 600+ Courses All in One Bundle
  • Login

HTTP Cookies

Home » Software Development » Blog » Software Development Basics » HTTP Cookies

Http Cookies

Introduction to HTTP Cookies

  • Here we will be learning about Http cookies. Well, before we move ahead to learn cookies, we must understand what Http is. Http is a protocol that facilitates the client-server communication. It is a connectionless protocol and here is exactly where the use of cookies comes in.
  • The term connectionless means, once the data gets exchanged between client and server, none of them could remember what they had exchanged lastly due to which the website admins were not able to understand the actions or surfing nature of the visitors. Now we will see how cookies get implemented and how does it works.
  • Cookies can be defined as the data that is stored by the server in the browser through which the web application was accessed. Once the connection is established between the client and the server, the client sends the request to the server and based on the response, some data has been saved in the browser. There are several purposes of storing the cookies in the client’s browser it could be for ensuring the authentication, for understanding the behavior of the user and so on.
  • Sometimes it’s also called browser cookies. Commonly it is also known as web cookies but preferably people recall it by the term cookies only. In a modern time when e-commerce is booming all across the world, the importance of cookies got magnified. It helps the business to understand what the users are looking for and how likely they are in order to buy something.
  • The social media websites make very efficient use of cookies to enforce good user experience and to protect their system from getting abused.

Create HTTP Cookies

So now we are aware of what HTTP cookies is and how it works in order to mitigate the HTTP connectionless problem. In this section, we will learn how we can create cookies and store them in the user’s browser. The values that are stored in the browser could be used for various purposes based on the requirement of the website. Below is the code to create the cookies.

<?php
// to set the cookie name
$cname = "Web_user1";
//to set the cookies value
$cvalue = "Amit Roy";
// to set the cookies.
setcookie($cname, $cvalue, time() + ( 3600));
?>

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The above code will set the cookies in the user’s system. setcookie is the method that is used to actually set the cookie. The syntax of the setcookie method is below.

setcookie(cookieName, cookieValue, cookielife)

In the above parameters, only the cookieName is mandatory else remaining are optional. Cookielife is the time till when the cookie will be stored in the browser. It is calculated in seconds. In the above example, its values are 3600 which means it will remain in the user’s browser for 1 hour.

Now let’s see how to use the cookie.

<?php if(!isset($_COOKIE[$cookieName)) {
echo "Please set '". $cookieName;
}
else
{
}
?>
echo "Cookie name is '". $cookie_name;

The above code will echo the cookieName value that was sent as a parameter through the setcookie function. The issue function checks if the variable has been assigned with some value. For the above code below will be the output.

The cookie name is Amit Roy.

Inspect HTTP Cookies with the browser

Now there is probably a high chance that you might be thinking if the cookies are stored is browser than where can you see this. Well, I will show you but before that let me tell you that any website cannot store cookies in your browser without your consent. Now let me show you where can you locate the cookies or the valued store by its mean.

HTTP Cookie1

In the above picture, you will be able to see that the website had stored some cookies in my browser. The image is of Firefox browser and I will tell you how you can locate cookies in Mozilla Firefox. You can follow the below steps to reach the screen that looks like the above one.

Popular Course in this category
Cyber Week Sale
All in One Software Development Bundle (600+ Courses, 50+ projects) 600+ Online Courses | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (3,144 ratings)
Course Price

View Course

Related Courses
Software Testing Training (11 Courses)Selenium Training Certification (9 Courses, 4+ Projects)Appium Training (2 Courses)JMeter Certification Training (3 Courses)

Step 1. Click on the three parallel lines that at the top right of the page.

Step 2. Click on the Web developer option.

Step 3. Click on Storage Inspector.

Step 4. Click on the website name for which you want to see the cookies.

HTTP Cookies path

Cookies path is the location in the server where the cookies are stored. In order to let the web pages access the cookies, the web pages must come under the subdirectory. By default, the cookie gets set at the global location from where it could be accessed by all the pages. Below is the code that can be used to set the global cookie.

document.cookie = ‘foo=bar; path=”/”’

In order to set the cookie in any subdirectory, you can use the below code. We have to be very careful while setting the cookie path as the pages that are a level up from the folder will not be able to access the cookies.

document.cookie = ‘foo=bar; path=”/subfolder”’

For instance, the page www.xyz.com/randompage1 will not be able to access the cookie while the page www.xyz.com/subfolder/randompage1 will be able to access it. If you don’t set the path, it will make the cookies global and could be accessible by every page.

HTTP Cookies security

  • Cookies are considered very crucial data for any website and are subject to kept confidential. There are headers in the HTTP request which are usually called HTTP packets which are used to provide security to the cookie.
  • There is an attribute, httponly, which makes the cookie accessible only from the host that has stored the cookies in the browser. It could not let the cookies to be pulled using the document. Cookie together with javascript.
  • document.cookie = ‘foo=bar; Secure;’// It will make the cookie inaccessible by the websites that are not transmitting the data without encryption. In simple terms, the communication between the browser and server must be encrypted by SSL/TSL. Url starting with https could be able to use it while the one with HTTP cannot.
  • document.cookie = ‘foo=bar; httponly;// By using httponly attribute, the cookies could be made inaccessible locally. It must need the request from the server in order to transmit the values set by cookies.

Conclusion

In a quick summary, cookies are considered as the set of code that is used to set some values to the browser that could be used the letter to gather information or to ensure security. The use of cookies is increasing day by day due to the security concern. All the modern websites vigorously store cookies in their user’s system so that they can understand how the user interacts with it.

Recommended Articles

This has been a guide to HTTP Cookies. Here we discuss an introduction, creation of cookies, cookie path, cookie security. You can also go through our other suggested articles to learn more –

  1. What is PHP?
  2. What is a Cyber Attack?
  3. What is Cyber Security?
  4. HTTP Caching

All in One Software Development Course Bundle

600+ Online Courses

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Reader Interactions
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar
Technology Blog Tutorials
  • Software Development Basics
    • Interoperability Testing
    • Code Coverage
    • Test Plan Template
    • Domain Testing
    • Sanity Testing
    • React Tools
    • What is Switch?
    • Adhoc Testing
    • Equivalence Partitioning
    • Recovery Testing
    • Software Development
    • Black Box Testing Techniques
    • What is XPath?
    • Listeners in TestNG
    • Array vs ArrayList
    • Git Checkout
    • Haskell Alternatives
    • What is Polymorphism?
    • TestNG Annotations
    • Unix File System
    • Shell Script Parameters
    • Software Quality Assurance
    • What is SDET?
    • UML Deployment Diagram
    • Fuzz Testing
    • What is Defect?
    • Automation Testing
    • Static Testing Techniques
    • Install GRUB
    • Spike Testing
    • Exception Handling in VB.NET
    • Unix File Permissions
    • Mutation Testing
    • What is a Bug in Software Testing?
    • Mantis Bug Tracker
    • Compatibility Testing
    • Components of Selenium
    • Overriding in OOPs
    • Iterator in C++
    • Free Web Hosting Sites
    • Interface Testing
    • Dynamic Testing
    • Non Functional Testing
    • Regression Testing Tools
    • Scalability Testing
    • Volume Testing
    • Negative Testing
    • Performance Testing Life Cycle
    • What is XPath in Selenium?
    • What is Test Automation Frameworks?
    • Bootstrap Typography
    • What is Laravel?
    • Hive Built-in Functions
    • Stability Testing
    • Levels of Software Testing
    • Software Testing Life Cycle
    • Types of Domain
    • VB.NET Controls
    • Types of Websites
    • What is Cucumber?
    • Best C Compilers
    • Manual Testing
    • UML Component Diagram
    • What is Stress Testing?
    • What is Debugging?
    • Test Harness
    • Diffie Hellman Key Exchange Algorithm
    • What is Functional Testing?
    • Constructor in C++
    • TFTP
    • What is Web Hosting?
    • Types of Software Testing
    • Benchmark Testing
    • UML Diagram Softwares
    • UML Object Diagram
    • Test Coverage
    • Gantt Chart Software
    • What is FTP?
    • Static Testing
    • Python Frameworks
    • What is Usability Testing?
    • HTTP Cookies
    • RMI Architecture
    • Selenium Architecture
    • Defect Tracking Tools
    • Performance Testing Tools
    • Monolithic Kernel vs MicroKernel
    • Cryptosystems
    • IPv6 Header Format
    • What is Cross Site Scripting?
    • User Datagram Protocol
    • SOA Testing
    • Test Case Design Techniques
    • What is SVN?
    • What is Debian?
    • Bootstrap Components
    • Bootstrap Layout
    • Windows Commands
    • Kotlin Functions
    • DBMS Keys
    • Selenium Grid
    • Selenium Tools
    • List of few Errors In Website
    • Introduction To GIT
    • Internet of Things (IoT) Applications
    • Is Cassandra NoSQL
    • What is OLTP?
    • Introduction To Algorithm
    • What is Juypter Notebook
    • Git Alternatives
    • Introduction To Android
    • GitHub Alternatives
    • Introduction to Windows
    • What is an Algorithm
    • What is Maven
    • What Is Apache
    • What Is SDLC
    • Sharepoint Alternatives
    • Selenium Alternatives
    • What is Selenium
    • What is Shell Scripting
    • What is Mainframe
    • What is Software Development
    • What is Git
    • What is Computer Science
    • Uses Of Powershell
    • What is SSRS
    • What is Application Server
    • What is RMAN Oracle
    • What is Virtual Host
    • What is Desktop Software
    • System Design Interview Questions
    • What Is System Design
    • What Is Design Pattern
    • What is MVC Design Pattern
    • System Analysis And Design
    • Application Software & Types
    • Learn the Art of Mechatronics
    • Myths & Misconceptions Software
    • Solve Problems With Technology
    • Avoid Pitfalls of Shadow
    • Learn to Code For Beginners
    • Software as a Service (Saas)
    • Freelance Web Designer
    • CISA Certification Exam
    • Programming Concepts
    • Defect Life Cycle in Software Testing
    • What is Visual Studio Code
    • Gray Box Testing
    • What is GPS
    • What is WIX
    • Bootstrap 4 Cheat sheet
    • Increase Productivity With New Technology
    • Uses of Salesforce
    • Uses of Selenium
    • Uses Of C#
    • IntelliJ Cheat Sheet
    • What is Spiral Model
    • Monolithic Kernel
    • Uses Of WordPress
    • What is a Greedy Algorithm
    • What is OSPF
    • Is MySQL Programming Language
    • Is Blockchain the Future
    • What is JMS
    • WordPress Work
    • What is Web Application
    • HTML Image Tags
    • Boolean operators in Java
    • What is WebSocket
    • Introduction To PHP
    • Advantages Of Array
    • Python 3 cheat sheet
    • How JavaScript Works
    • Is Blockchain Safe
    • What is PLC
    • What is Threading
    • How Blockchain Works
    • SoapUI Alternatives
    • What is Microcontroller
    • Advantages of PHP
    • PHP Alternatives
    • Ubuntu Alternatives
    • WordPress Alternatives
    • Linux Alternatives
    • What is SOAP
    • Introduction To Computer Network
    • Windows Operators
    • Android Alternatives
    • What is PowerShell
    • What is Elasticsearch
    • Algorithm in Programming
    • JIRA Alternatives
    • Wix Alternatives
    • PowerShell Operators
    • What is Laravel Framework
    • SOA Alternatives
    • Is Ansible free
    • Laravel Commands
    • What is Blockchain Technology
    • What is Bootstrap
    • What is Unix
    • What is Ansible
    • What is Software Testing
    • Windows Alternatives
    • What is Jira Software
    • What is UI Designer
    • What is VBScript
    • What is SoapUI
    • Uses of Ubuntu
    • What is MVC
    • What is ASP.NET
    • What is Multithreading
    • What is ASP.Net Web Services
    • What is TFS
    • What is DBMS
    • What is Embedded Systems
    • Inheritance in VB.Net
    • What is VMware?
    • What is Open-Source License
    • What is Bot
    • What is Open Source
    • What is ETL Testing
    • What is GraphQL
    • cPanel vs Plesk
    • System Software Tools
    • Information Technology Benefits
    • Black Box Testing
    • What is ETL
    • What is IDE
    • Uses of Coding
    • Uses Of Raspberry Pi
    • What is Hypervisor
    • Website Services
    • What is Common Gateway Interface
    • White Box Testing
    • Web Testing Application
    • OS Alternatives
    • Iterative Model
    • What is Unix Shell
    • Automation Testing Tools
    • Integration Testing
    • System Testing
    • Unit Testing
    • Test Automation Framework
    • Alpha and Beta Testing
    • Decision Table Testing
    • Regression Testing
    • Types of Algorithms
    • What is Appium
    • Prototype Model
    • What is CLI
    • Waterfall Model
    • RAD Model
    • Ray Tracing Algorithm
    • OpenGL in Android
    • Types of UML Diagrams
    • Class Diagram
    • What is Assembly Language
    • ASP.NET Page Life Cycle
    • HTTP Caching
    • What is Selenium Web Driver
    • Selenium Framework
    • Selenium Testing
    • Selenium Automation Testing
    • What is Buffer Overflow
    • What is Joomla
    • What is Virtualization
    • What is WCF
    • What is OOP
    • What is SOA
    • What is JDBC
    • What is Clickbait
    • What is GUI
    • What is FreeBSD
    • Software Testing Principles
    • System Integration Testing
    • What is CMD
    • What is VB.Net
    • What is CodeIgniter
    • UML Use Case Diagram
    • What is WordPress
    • UML Activity Diagram
    • What is Coding
    • UNIX ARCHITECTURE
    • Random Forest Algorithm
    • UML Sequence Diagram
    • DOS vs Windows
    • What is SVG
    • What is QTP
    • VB.NET Operators
    • What is MuleSoft
    • What is Exploratory Testing
    • What is Ransomware
    • Sublime Text Alternatives
    • What is Static Routing
    • Kotlin vs Swift
    • GUI vs CLI
    • What is CentOS
    • What is Template Class in C++
    • What is Apex
    • StringBuffer vs StringBuilder
    • DES vs AES
    • Encryption vs Decryption
    • Dynamic Routing
    • Cyclomatic Complexity
    • Encryption Algorithm
    • Install Kali Linux
    • Alpha Testing vs Beta Testing
    • What is DHCP
    • Basic HTML Tags
    • Advantages of C
    • ASP.Net Validation Controls
    • What is CSRF
    • Network Mapper
    • Loops in C++
    • Loops in C
    • EJB vs Spring
    • Switch Statement in C
    • CentOS Commands
    • Digital Signature Softwares
  • Database Management (71+)
  • Ethical Hacking Tutorial (33+)
  • HTML CSS Tutorial (47+)
  • Installation of Software (54+)
  • Top Interview question (188+)
  • Java Tutorials (196+)
  • JavaScript (71+)
  • Linux tutorial (32+)
  • Network Security (85+)
  • Programming Languages (232+)
  • Python Tutorials (89+)
  • Software Development Careers (38+)
  • SQL Tutorial (33+)
  • String Functions (12+)
  • Technology Commands (38+)
  • Top Differences (368+)
  • Web Development Tools (33+)
  • Mobile App (60+)
Technology Blog Courses
  • Software Testing Training
  • Selenium Training Certification
  • Appium Training
  • JMeter Certification Training
Footer
About Us
  • Who is EDUCBA?
  • Sign Up
  •  
Free Courses
  • Free Course Programming
  • Free course Python
  • Free Course Java
  • Free Course Javascript
  • Free Course on SQL
  • Free Course on Web Design
  • Free HTML Course
  • Free Android App Development Course
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • Ruby on Rails Course
  • ASP.NET Course
  • VB.NET Course
  • Bootstrap Training Course
  • Become a Linux System Administrator
  • PHP Course
  • Joomla Training
  • HTML Course
Resources
  • Resources (A To Z)
  • Java Tutorials
  • Python Tutorials
  • Top Differences
  • Top Interview Question
  • Programming Languages
  • Web Development Tools
  • HTML CSS Tutorial
  • Technology Basics
  • Technology Careers
  • Ethical Hacking Tutorial
  • SQL Tutorials
  • Digital Marketing
Apps
  • iPhone & iPad
  • Android
Support
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions

© 2019 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Let’s Get Started
Please provide your Email ID
Email ID is incorrect

Limited Period Offer - All in One Software Development Course Bundle View More

Limited Period Offer - Limited Period Offer - All in One Software Development Course Bundle View More