A question about cookies

Source: Internet
Author: User
Tags send cookies setcookie
Level two domain name a.c.com and b.c.com

If I request A.c.com's a.php,a.php POST request b.c.com b.php, set the cookie in b.php.

This way, does the cookie exist on the server? Instead of on the client I requested?

How to fix it, thank you


Reply to discussion (solution)

Cookies are saved on the client.
There are domain name restrictions on the read and write of cookies.

You write the cookie to. c.com This domain can share cookies at two sites

You should look carefully at the PHP manual. bool Setcookie (String $name [, String $value [, int $expire [, String $path [, String $domain [, BOOL $secure [, BOOL $httponly]]]]] [with Setcookie function, an optional argument is a string $domain this is the role domain name, for example, you want to set www.aa.com and bbs.aa.com equally valid for this parameter ". AA.com" Remember the one in front.

You should look carefully at the PHP manual. bool Setcookie (String $name [, String $value [, int $expire [, String $path [, String $domain [, BOOL $secure [, BOOL $httponly]]]]] [with Setcookie function, an optional argument is a string $domain this is the role domain name, for example, you want to set www.aa.com and bbs.aa.com equally valid for this parameter ". AA.com" Remember the one in front.

Upstairs two said I know, is not I do not express clearly, is the middle of a more intermediary, the cookie can also be saved on the original request of the client?

Upstairs two said I know, is not I do not express clearly, is the middle of a more intermediary, the cookie can also be saved on the original request of the client?
If you do not have a proxy, it should be present on your local client. You go to the C-disk and look for it.

Cookies are always stored on the client
Only cookies that have the expiration period set will be saved as a file named after the domain name.

Cookies are always stored on the client
Only cookies that have the expiration period set will be saved as a file named after the domain name.
I did a test:
1.php

$res = file_get_contents ("http://a.c.com/2.php?k1=123&k2=456"); Var_dump ($res); exit;


2.php
$k 1= $_request[' K1 ']; $k 2= $_request[' K2 '];setcookie ("K1", $k 1, Time () + 7 * 2 * 3600, '/', '. c.com '); Setcookie ("K2", $k, Time () + 7 * 3600, '/', '. c.com '); echo "OK";


After requesting 1.php, the display is OK, but the browser does not see the cookie

Yes, the browser is not Cooke.
Because cookies are things that are browsers, and file_get_contents are file operations, they are irrelevant.

Yes, the browser is not Cooke.
Because cookies are things that are browsers, and file_get_contents are file operations, they are irrelevant.
I still can't understand, I wonder if this cookie has been set successfully, and then the browser requests it again. c.com domain name, can you get this cookie?

Yes, the browser is not Cooke.
Because cookies are things that are browsers, and file_get_contents are file operations, they are irrelevant.
I would like to express the browser view cookie function does not see the above set of cookies, in addition to the File_get_contents,curl get and post I have tried

The HTTP headers emitted by the 2.php are ignored by file_get_contents (only the body part), so the Set-cookie instructions are not executed
So the cookie doesn't exist.

Cookies can only be carried with browser or curl access

Of course, file_get_contents can also send cookies through the context property, but not to get

The HTTP headers emitted by the 2.php are ignored by file_get_contents (only the body part), so the Set-cookie instructions are not executed
So the cookie doesn't exist.

Cookies can only be carried with browser or curl access
Well, I understand that the above-mentioned file_get_contents why not set a cookie, ask what method can make 2.php cookie set success, I tried to use curl get and post also not, thank you

You'd better read the manual and the articles on the internet first.
It's not school, after all.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.