Cookies-php setcookie suddenly cannot work?

Source: Internet
Author: User
I suddenly found that the setcookie of php could not work, and it took almost an hour. Part of the index code: {code...} setc. php all code: {code...} is mainly a logon function, but setcookie is always invalid. The chromeurl column shows a user's cooki...

I suddenly found that the setcookie of php could not work, and it took almost an hour.
IndexSome code:

......《script》    function login(){        var a=$("#uname").val();        var b=$("#up").val();        var c=$("#yzm").val();        $.ajax({            method: "post",            url: "setc.php",            data: {uname: a, up: b, yzm: c},            success: function (msg) {                alert(msg);            },            complete: function (XHR, TS) { XHR = null }        });    }《script》    
  

......

Setc. phpAll code:


  

It is mainly a logon function, but setcookie is always invalid.
In the chrome url bar, you can see a user's cookie. val is also correct, that is, there is no refresh, and I don't know why.
This strange cookie is not found in the Development workbench.
There is a cookie here, but there will be no refresh.

Cookie not found here

I have changed ie and ff, and they are all the same results. Ask the experts for answers.

Reply content:

I suddenly found that the setcookie of php could not work, and it took almost an hour.
IndexSome code:

......《script》    function login(){        var a=$("#uname").val();        var b=$("#up").val();        var c=$("#yzm").val();        $.ajax({            method: "post",            url: "setc.php",            data: {uname: a, up: b, yzm: c},            success: function (msg) {                alert(msg);            },            complete: function (XHR, TS) { XHR = null }        });    }《script》    
   

......

Setc. phpAll code:


   

It is mainly a logon function, but setcookie is always invalid.
In the chrome url bar, you can see a user's cookie. val is also correct, that is, there is no refresh, and I don't know why.
This strange cookie is not found in the Development workbench.
There is a cookie here, but there will be no refresh.

Cookie not found here

I have changed ie and ff, and they are all the same results. Ask the experts for answers.

Setcookie parameter settings are incomplete, reference http://php.net/manual/zh/function.setcookie.php

setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] )

If path is not set for the third parameter, it is valid in the current path where setcookie is located by default, that is, the cookie you set is only valid under/tpok/login in the logon path, the cookie cannot be found after the page jumps.

setcookie("user", $cookie, strtotime( '+7 days' ), "domain or path");

Set the path/

If no path is set for setcookie, the default path is the path of the current page. The page in the parent path cannot be accessed.

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.