পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 22, 2017

Yii - Cookies

Cookies are plain text files stored on the client side. You can use them for tracking purpose.
There are three steps to identify a returning user −
  • Server sends a set of cookies to the client (browser). For example, id or token.
  • Browser stores it.
  • Next time a browser sends a request to the web server, it also sends those cookies, so that the server can use that information to identify the user.
Cookies are usually set in an HTTP header as shown in the following code.
HTTP/1.1 200 OK
Date: Fri, 05 Feb 2015 21:03:38 GMT
Server: Apache/1.3.9 (UNIX) PHP/4.0b3
Set-Cookie: name = myname; expires = Monday, 06-Feb-16 22:03:38 GMT;
   path = /; domain = tutorialspoint.com 
Connection: close
Content-Type: text/html
PHP provides the setcookie() function to set cookies −
setcookie(name, value, expire, path, domain, security);
where −
  • name − Sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS.
  • value − Sets the value of the named variable.
  • expiry − Specifies a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible.
  • path − Specifies the directories for which the cookie is valid.
  • domain − This can be used to define the domain name in very large domains. All cookies are only valid for the host and domain which created them.
  • security − If set to, it means that the cookie should only be sent by HTTPS, otherwise, when set to 0, cookie can be sent by regular HTTP.
To access cookies in PHP, you may use the $_COOKIE or $HTTP_COOKIE_VARS variables.
<?php 
   echo $_COOKIE["token"]. "<br />"; 
   /* is equivalent to */ 
   echo $HTTP_COOKIE_VARS["token"]. "<br />"; 
   echo $_COOKIE["id"] . "<br />"; 
   /* is equivalent to */ 
   echo $HTTP_COOKIE_VARS["id"] . "<br />"; 
?>
To delete a cookie, you should set the cookie with a date that has already expired.
<?php 
   setcookie( "token", "", time()- 60, "/","", 0); 
   setcookie( "id", "", time()- 60, "/","", 0); 
?>

No comments:

Post a Comment