0

I am checking for the availability of Cookie variables via echo in the browser called script like so

var_dump($_COOKIE);

and via frwite in the Apache RewriteMap since it can't echo to anything, like so

fwrite($fh, var_export($_COOKIE, true));

also note that the session value of interest is passed to the script from apache like so

RewriteCond %{HTTP_COOKIE} \bsid=[0-9a-z]{32}\b
RewriteRule ^   -   [E=SID:%1]
RewriteCond ${prg:%{ENV:SID}} =true

The browser called script shows the correct cookie entries/values, but the RewriteMap script shows an empty cookie. I wonder if this is because RewriteMap requires its scripts to enter an infinite loop waiting for standard in. Alternatively, could it have anything to do that the browser script is using suPHP while Apache might be calling just plain old PHP. I am still debuging and it might be the case that I made a mistake somewhere, but I wanted to know if this was something different entirely.

puk
  • 16,318
  • 29
  • 119
  • 199

2 Answers2

0

Not sure if this is relevant, but...

I set a cookie from a PHP script (called by AJAX) and tried to access by Javascript and it couldn't find it.

The reason was that my PHP scripts are in a folder /php, so the cookie ended up in /root/php not in /root. So maybe check that all the scripts are setting and getting cookies to/from the same place :)

Nick
  • 5,995
  • 12
  • 54
  • 78
  • Could you please provide an example of how you are setting the cookie as I am not sure what you mean by 'in a folder' (I am a cookie noob) – puk Mar 18 '12 at 03:04
  • In PHP, setting a cookie is done like this: setcookie(name, value, expire, path, domain); Only the first two arguments are necessary (i.e., name and value). Retrieving a cookie is very easy - you just refer to a variable name like a $_SESSION, $_POST or $_GET variable: $_COOKIE["name"]; The difficulty may stem from the fact, however, that the domain and/or path of the cookies are not the same. What I mean by "in a folder" is that my PHP scripts reside in a folder one level below public_html (e.g., public_html/php/php_script.php). Any cookie they create is put in that folder (it seems). cont... – Nick Mar 18 '12 at 06:00
  • When I tried to access the PHP-created cookies using Javascript, the JS said they "weren't there". Actually, however, when I used Firefox and clicked the image to the left of the URL, it showed the cookies had been created but were in the different level folder. At no point did I specify a domain/path or try and put them in a folder; that's just the default for the PHP. My suggestion for your problem was, therefore, to check the domain/path of the cookies. Perhaps the Rewrite script is looking in a different domain/path. Hope this makes it clearer - I'm not confident it will :) – Nick Mar 18 '12 at 06:01
  • well I have the cookie set in the document root folder and the domain set to `.example.com` (`setcookie( 'x', 0, time()+30*3600, '/', '.example.com' )`) so every subdomain will also have access to it. Do you have any idea how I could find out what folder rewriteMap is looking in? – puk Mar 18 '12 at 07:18
  • Not really, sorry. Is this of any help? http://stackoverflow.com/questions/8453554/apache-rewritemap-used-to-prevent-direct-access-to-files – Nick Mar 18 '12 at 09:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9016/discussion-between-puk-and-nick) – puk Mar 18 '12 at 17:08
  • Sorry I've fallen off the face of the planet, @puk. Life gets a little too busy sometimes :) – Nick Mar 28 '12 at 11:44
0

Turns out the problem was an incorrect regular expression. The line that was capturing the cookie value was missing a pair of parantheses:

RewriteCond %{HTTP_COOKIE} \bsid=[0-9a-z]{32}\b

And therefore, the matched cookie was inaccessible, all I had to do was change the above line to

RewriteCond %{HTTP_COOKIE} (\bsid=[0-9a-z]{32}\b)
puk
  • 16,318
  • 29
  • 119
  • 199