cappo Posted July 28, 2009 Share Posted July 28, 2009 Hi there! I am new to this board and I hope someone can help me with a little problem of mine. The whole thing can be summarized as follows: Is it possible to read cookies in a php-script which has been called using AJAX? If so, how? I'll give you a more detailed example of what I need: I have a website, which uses two cookies: One with the username, one with the password. There is page which calls a PHP-Script using AJAX (to be more precise: I use SAJAX). This PHP-Script needs to know the information stored in the two cookies. Just reading the cookies as normal does not seem to work when I call the script using AJAX. I want to avoid reading the cookies on the original page and then passing on the values to the php-script, because of security concerns. I really appreciate any help! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 These two statements seam to conflict! I have a website, which uses two cookies: One with the username, one with the password. I want to avoid reading the cookies on the original page and then passing on the values to the php-script, because of security concerns. PHP can read cookies like so echo $_COOKIE['insecure']; //returns data Quote Link to comment Share on other sites More sharing options...
cappo Posted July 28, 2009 Author Share Posted July 28, 2009 Hi, thank you for your answer. Actually the two statements do not conflict. When talking about "a website" I should have written something like my "internet project in general" or so. To clarify: - I have two cookies already set. - I have a website which does not read those cookies. This website calls a php script using AJAX. - The called php script needs the infos written in those two cookies. - echo $_COOKIE['insecure']; works when I call the PHP script directly - echo $_COOKIE['insecure']; does NOT work for me when I call the PHP script using AJAX - I want to know how I can read the cookie when calling the PHP script using AJAX. At least with SAJAX as a framework it does not seem to work "the normal way" Quote Link to comment Share on other sites More sharing options...
cappo Posted July 28, 2009 Author Share Posted July 28, 2009 Okay, I found the error. For some odd reason $HTTP_COOKIE_VARS["cookiename"] does not work in a PHP script called with AJAX. It works in a direct call. $_COOKIE[cookiename] -as suggested by MadTechie- works with AJAX. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.