Cookie Monster! Session ID disappears with mod_rewrite ...

Using a single web hosting account to host multiple sites

Cookie Monster! Session ID disappears with mod_rewrite ...

Postby madhtr » Wed Jan 31, 2007 3:54 pm

Forgive me, I'm an ASP developer trying PHP :)

I have seen this issue sort of addressed here in about 3 posts, but no solution that works so far ...

I am hosting multiple domains on one server/static IP address via mod_rewrite. I always use session variables via cookies, I don't want to put then in a query string for security reasons.

Win 2000
Apache 2.2.3
PHP 5.2.0

- I have added an entry, 127.0.0.1 domain_one, in my hosts file.
- I have created htdocs\domain_one\index.php.

The following works fine in htdocs (localhost), but fails when it gets redirected to htdocs\domain_one. (domain_one)

.htaccess ...
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST}  domain_one$ [NC]
RewriteCond %{REQUEST_URI} !^/domain_one/.*$
RewriteRule ^(.*)$  /domain_one/$1 [L]

\domain_one\index.asp ...
Code: Select all
<?php
session_start();
if (!isset($_SESSION['count'])) {
   $_SESSION['count'] = 0;
} else {
   $_SESSION['count']++;
}
?>
<html>
<head>
<title>PHP Session Test</title>
</head>
<body>
Session Id is not preseved... on Refresh or via the link ...<br>
<?php
   echo "SESSION ID: " . session_id();
   echo "<br><br>count: ". $_SESSION['count'];
   echo "<br>";
?>
<br>
<a href="index.php">cycle this page via a link</a>
</body>
</html>

will someone PLEASE tell me what I am doing wrong, or if this can be done at all hehe :)

<e>edited, discovered 'code' tag, sry, heh ;)</e>
madhtr
 
Posts: 3
Joined: Wed Jan 31, 2007 2:56 pm

Ok, Update ...

Postby madhtr » Thu Feb 01, 2007 9:25 am

OK ... Netscape AND Firefox work fine!

Its only IE7 that has this problem. (sends cookie to the Bermuda Triangle after mod_rewrite). Dunno about IE6 yet. Default Security Settings. I tried letting ALL cookies in, still failure. I used an HTTP header viewer in IE, and the HTTP repsponse header includes the set-cookie field, and it reads:

Set-Cookie PHPSESSID=d8bgpj6mlq63289q92v6tkr384; path=/

Looks fine to me .... why is IE7 blowing off this cookie when NS and FF do not? have I discovered a major IE7 bug?

any ideas?
madhtr
 
Posts: 3
Joined: Wed Jan 31, 2007 2:56 pm

Postby madhtr » Thu Feb 01, 2007 12:28 pm

PROBLEM SOLVED:

.htaccess
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST}  dev_unitec$ [NC]
RewriteCond %{REQUEST_URI} !^/unitec/.*$
RewriteRule ^(.*)$  /unitec/$1 [L]


see http://usphp.com/manual/ro/ref.session.php
see the comment posted by 'marcosdsanchez' ...

"...There's a bug in Internet explorer in which sessions do not work if the name of the server is not a valid name. For example...if your server is called web_server (_ isn't a valid character), if you call a page which uses sessions like http://web_server/example.php your sessions won't work but sessions will work if you call the script like this

[IP NUMBER]/example.php

Took me a lot of time to find out why my PHP sessions worked perfectly in Firefox and Opera but they didn't work in internet explorer ..."


Ok, notice that my "domain name" has an underscore in it. I took the underscore away and it all works fine now.

So ... INTERNET EXPLORER is the cookie monster, NOT mod_rewrite! I hope this will be of some help to others ;)
madhtr
 
Posts: 3
Joined: Wed Jan 31, 2007 2:56 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 35 guests

cron