PHP and Javascript cookies

后端 未结 2 1169
长发绾君心
长发绾君心 2021-01-16 11:32

Can I access a cookie written with jQuery\'s cookie plug-in with PHP? I know you can\'t set Javascript equal to PHP or vice versa, but IN ESSENCE is:

$.cook         


        
2条回答
  •  深忆病人
    2021-01-16 12:32

    Yes.

    But... Klaus Hartl's jQuery cookie plugin (I'm assuming this is the one you are using) defaults to setting the cookie's path to that of the current document. If the PHP file you were trying to echo from was in a different folder, the cookie wouldn't have been sent.

    You can set the cookie's path when you set the cookie:

    $.cookie('name', val, { path: '/' });
    

提交回复
热议问题