Skip to content
FullStackDost Logo
  • All Courses
  • Blogs
  • Login
  • Register
  • All Courses
  • Blogs
  • Login
  • Register
  • Home
  • All Courses
  • Full Stack Development
  • PHP Tutorial

PHP Tutorial

Curriculum

  • 6 Sections
  • 29 Lessons
  • 3 Weeks
Expand all sectionsCollapse all sections
  • PHP Tutorials
    PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for web development.
    3
    • 1.1
      PHP Introduction
      20 Minutes
    • 1.2
      PHP Installation
      15 Minutes
    • 1.5
      PHP Syntax
      35 Minutes
  • PHP Basics
    PHP Basics Unleashed: Dive into the Fundamentals of Web Development!
    10
    • 2.0
      PHP Variables
      30 Minutes
    • 2.1
      PHP Arrays
      35 Minutes
    • 2.2
      PHP Conditions
      40 Minutes
    • 2.3
      PHP Loops
      45 Minutes
    • 2.4
      PHP Functions
      40 Minutes
    • 2.5
      PHP Array Functions
      20 Minutes
    • 2.6
      PHP String Functions
      35 Minutes
    • 2.7
      PHP Superglobals
      25 Minutes
    • 2.8
      PHP GET & POST
      30 Minutes
    • 2.9
      PHP Cookies
      45 Minutes
  • PHP Forms
    Streamline Your Web Forms: Master PHP Form Handling for Seamless User Interactions!
    3
    • 3.0
      PHP Forms
    • 3.1
      PHP Form Validation
      35 Minutes
    • 3.2
      PHP Form essentials
      20 Minutes
  • PHP Advance Topics
    Advanced topics in PHP cover a range of more complex concepts and techniques that are useful for experienced developers looking to build sophisticated web applications.
    8
    • 4.0
      PHP Date and Time
      35 Minutes
    • 4.1
      PHP File Handling
      45 Minutes
    • 4.2
      PHP Sessions
      35 Minutes
    • 4.3
      PHP Filters
      35 Minutes
    • 4.4
      PHP OOPS
      60 Minutes
    • 4.5
      PHP Traits
      45 Minutes
    • 4.6
      PHP Interface
      40 Minutes
    • 4.7
      PHP File upload
      45 Minutes
  • PHP Security
    Fortify Your PHP Skills: Learn Essential Security Practices to Safeguard Your Web Applications!
    1
    • 5.0
      Securing PHP application
  • Discussions on PHP
    Unlock the Power of PHP: Balancing Conciseness and Clarity for Readable Code Mastery
    4
    • 6.0
      Advantages of PHP
    • 6.1
      Disadvantages of PHP
    • 6.2
      Performance of PHP
    • 6.3
      Comparison with Node/JavaScript

PHP Cookies

In PHP, cookies are small pieces of data sent by the server to the client’s browser, which are then stored on the client’s computer. Cookies are commonly used for session management, user tracking, and personalization. Here’s an overview of PHP cookies along with examples:

Setting Cookies:

You can set cookies using the setcookie() function. Cookies must be set before any HTML output.

Syntax:

setcookie(name, value, expire, path, domain, secure, httponly);

Example:

setcookie("username", "John", time() + 3600, "/"); // Expires in 1 hour

Accessing Cookies:

Cookies are stored in the $_COOKIE superglobal array and can be accessed like any other associative array.

Example:

echo $_COOKIE["username"]; // Output: John

Deleting Cookies:

To delete a cookie, you can set its expiration time to a past value.

Example:

setcookie("username", "", time() - 3600, "/"); // Expire immediately

Cookie Parameters:

  • name: The name of the cookie.
  • value: The value of the cookie.
  • expire: The expiration time of the cookie (in seconds since the Unix Epoch). If not set, the cookie will expire when the browser is closed.
  • path: The path on the server for which the cookie is available. If set to ‘/’, the cookie will be available for the entire domain.
  • domain: The domain for which the cookie is available. Default is the current domain.
  • secure: Indicates if the cookie should only be transmitted over HTTPS.
  • httponly: Indicates if the cookie should only be accessible through HTTP.

Using Cookies for Persistent Login:

if (isset($_COOKIE["username"])) {
 $username = $_COOKIE["username"]; // Check if username exists in database and log in the user
} else {
 // Prompt user to log in
}

Note:

  • Cookies have size limitations (usually around 4KB).
  • Cookies are sent with every HTTP request to the server, which can impact performance.
  • Be cautious when storing sensitive information in cookies, as they are stored on the client’s machine and can be manipulated.

Cookies are a fundamental aspect of web development, allowing you to store and retrieve data on the client’s machine. They are commonly used for session management, user authentication, and personalization in PHP applications.

PHP GET & POST
Prev
PHP Forms
Next

Copyright © 2025 FullStackDost. All Rights Reserved.

Theme by ILOVEWP