Get the cookie value in PHP?

前端 未结 3 614
情深已故
情深已故 2021-01-16 05:16

I create the cookie in jQuery. I can verify it in Firefox. But when I try to print the cookie or assign into another value I cant get it. I also use sessions. And I started

3条回答
  •  死守一世寂寞
    2021-01-16 06:05

    It is possible to set the cookie in PHP entirely without jQuery at all..

    ..however...

    It appears you are using jQuery in this way.

    What may be causing a problem is a few things:

    a) $(this).val() possibly might be returning NULL.

    b) You are not setting the path and expiration on the cookie. If you have subdirectories it is normally good to set a master cookie that is the root path '/'.

    To read your cookie using PHP, try this...

      $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
    

    ...and search the array for your "a" cookie.

    Further docs on setting and reading cookies using entirely PHP, check here.

    You must call this function before any other code is echoed to the page. (before headers)

提交回复
热议问题