PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] How to share cookies across multiple Apache Virtual Hosts

 January 13, 2022     cookies, lamp, virtualhost     No comments   

Issue

This question is generally phrased as "How to share cookies across multiple subdomains" and the answer is generally to use the leading dot like so

setcookie( 'id', 0, time()+30*3600, '/', '.example.com' );

which means that the cookie is available to all subdomains of example.com. However, the / path I suspect adds the constraint that all subdomains must be physically under the same tree. The PHP documentation states

path

The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.

Is it possible to share cookies if one has two (Apache) Virtual Hosts set up with document roots at, for example

  • www.one.example.com → /var/www/example1
  • www.two.example.com → /var/www/example2

Solution

Yes it will work.

The path segments of the cookies are based on the URI.

www.one.example.com and www.two.example.com both have / as the URI. The cookie doesn't have anything to do with where the virtual host resolves to.



Answered By - Jay Prall
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing