Home > Backend Development > PHP Tutorial > Share the method of php using P3P to complete COOKIE cross-domain operations

Share the method of php using P3P to complete COOKIE cross-domain operations

WBOY
Release: 2016-07-25 08:57:59
Original
823 people have browsed it
  1. 127.0.0.1 www.a.com
  2. 127.0.0.1 www.b.com
Copy code

First: Create a_setcookie.php file:

  1. //header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  2. setcookie("test ", $_GET['id'], time()+3600, "/", ".a.com");
  3. ?>
Copy the code

Then: Create a_getcookie.php file:

  1. var_dump($_COOKIE);
  2. ?>
Copy code

Finally: Create b_setcookie.php file:

Copy code

Three After the files are created, access them sequentially through the browser:

  1. http://www.b.com/b_setcookie.php
  2. http://www.a.com/a_getcookie.php
Copy the code

while visiting the b.com domain, and There is no cookie value set in the a.com domain.

Then, modify the a_setcookie.php file and remove the comment symbols. a_setcookie.php is:

  1. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  2. setcookie("test", $_GET['id'], time()+3600, "/", ".a.com");
  3. ?>
Copy the code

Visit through the browser again:

  1. http://www.b.com/b_setcookie.php
  2. http://www.a.com/a_getcookie.php
Copy the code

to see if cross-domain has been implemented Visited.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template