Follow up: cookies and redirect
| From: | Andrea Resmini | Date: | Sun, 03 Dec 2000 16:44:17 +0000 |
| Subject: | Follow up: cookies and redirect | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-28448@lists.php.net to get a copy of this message | ||
Ok, after some testing this is what I found out:
Opera on Linux does not set correctly neither HTTP_REFERER nor (quite
obviously) HTTP_SERVER_VARS(HTTP_REFERER), and I suspect this also
applies to IE 4, at least in some conditions, since all started with a
client's report of this redirect thing not working on IE 4 and Windows
(the servers are the same, and my company's: they run Linux with Apache
1.3.12 and PHP 4.03) and I verified exactly the same behaviour in Opera
for Linux on a testcase server using the above configuration.
Mind you, if I load up phpinfo() using Communicator I get both vars,
meaning Apache sets them. If I load it up with Opera, no sign of them.
So, since basically I was using the referer to reload the original page
after language switch, everything fell down: I got cookies, but no
redirect. I mended the script adding another pass-along var, $requester,
which I set from the calling script (fortunately PHP_SELF exists in
Opera also), so I can reload it nonetheless. Not very clean maybe, but
it works.
If anybody is interested in more details or can fill some blanks here
and there, here's what I did in detail.
a. Upon site entering, a language cookie is set to the default site
language
b. A routine checks for active languages for the site, in the form of
sql tables, and prints links accordingly, taking out the current
language. Each link looks a bit like this (sorry for the long line):
<a
href="switchlanguage.inc.phtml?language=en&requester=<callingfile>&screen=<callingscreen>"Click
here for English</a>
where $requester is the PHP_SELF value for the calling file and $screen
is an internal var telling the calling script which subfunction
activate, if any (not relevant for the example).
c. When a user clicks, the switchlanguage script gets called. It
produces no output, but sets the language cookie to the one passed along
by the link (en, in this case) and then redirects back to <callingfile>
using header().
When this was simply using HTTP_REFERER and not $requester, as detailed
above, it didn't work on Opera (and IE). Now it works (and tomorrow
morning I'll check with IE).
I hope you'll excuse the long post, but I think someone could benefit
from this.
--
Andrea Resmini
a.resmini@ogcs.com
hypermedia development, OGCs.com
http://www.ogcs.com