Jump to content

[SOLVED] Ajax and Cookies


cappo

Recommended Posts

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!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.