PDA

View Full Version : Newbie PHP3 session control question


esc
04-11-2001, 03:12 AM
Hi,

I’m building a multi-lingual site that will be hosted on a Apache server with only PHP3 installed. This site consists of a bunch of page templates with filled in text-blocks. The texts are included dynamically using PHP according the selected language. The initial information will be read from the HTTP-Header of the first requested page or if not possible default to one of the implemented languages. The possibility to change the language on every page is provided.

What mechanism can and should I use to propagate the language-selection from page to page. I do not want to use cookies.

Regards,
Erich

jbroder
04-11-2001, 11:06 PM
you can set a session_variable, like this:

PAGE 1: set the variable:
session_register("language");
$language = 'russian';

PAGE 2: get the variable:
session_register("language");
if ($language == 'russian') {
[nbsp]// do russian language text here.
}

PaulKroll
04-12-2001, 12:55 AM
He said PHP3: there's no session_() functions in PHP3. Further, he said no cookies: the PHP4 session functions default to using cookies and only use a GET variable (default of PHPSESSID) if the browser doesn't support cookies.

I used PHPLIB (check the PHP site for a link, http://www.php.net, links section) under PHP3, but it's a cookie user.

The only viable way of doing this without cookies is going to be setting a variable in each link, i.e., have every href="/something.html" get a "?Lang=FR" or something similar, attached. If a URL already has a variable or two, this gets a bit tricky.

Cookies are a pretty vital thing. It's unfortunate that some uses (i.e., the advertising servers...) have been less-than-joyously-accepted, shall we say.

Rich
04-12-2001, 02:19 AM
The initial information will be read from the HTTP-Header of the first requested page or if not possible default to one of the implemented languages. The possibility to change the language on every page is provided.
The option to change the language should be a link that regenerates the page with the appropriate language header. Then you will be already to re-read the header again on subsequent pages to keep displaying in the selected language until changed again. (Browsers maintain the encoding until changed again.)

<edit>
That last sentence should read &quot;The browser will maintain...&quot;.
</edit>

Rich
[This message has been edited by Rich (edited 04-12-01@01:22 am)]

esc
04-12-2001, 04:52 AM
Thank you to everybody for your comments.

First let me explain the restriction we have to face in case of this job. The customer insists on a layout which we can only provide for IE5.5 and above as it requires transparent, stackable IFRAMES with CSS positioning. Therefore we develop a second parallel simplified version for the other browsers. This version should work even for paranoia settings (CSS, JavaScript and cookies disabled). As the site comes in three languages we would have to maintain 6 versions, if we do not collapse the branches. Therefore we assemble the pages dynamically and have to keep book of the branch we are in.

The web space provider (KPNQWest) of our customer has just upgraded his installation from PHP3 to PHP4 as I noticed this morning. But PHP4 it is still a CGI and I believe I have read somewhere on the web that there are some restrictions in the session handling or no session mechanism at all, as the CGI module unloads from memory every time after processing a page (or something like this – I could not find it in the PHP manual). Anyway, I will make a test page and give it a try.

To Jonathan and Paul:

If I understand it right (I’ve looked into the manual) and get the session mechanism to work, I have the choice to propagate the session ID with either cookies or URL parameters.

To Rich:

I get the language information from parsing the HTTP header of the page or the Apache predefined variables, especially HTTP_ACCEPT_LANGUAGE which contains a string like “de-at,de;q=0.7,en-us;q=0.3” or similar. I believe you are speaking about the HTML header of the page like

<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-2&quot;>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;cs&quot;>

This information is not sent to the server when following a link (at least I couldn’t find it) and I would have to use JavaScript (or similar) to get it from the DOM and put the language handling on the client side.

Of course we adapt the encoding of the pages if necessary (e.g. Latin-2 for the eastern European languages). Otherwise we would loose a lot of the accents and fancy characters when displayed on a browser with different default settings.

Erich

Rich
04-12-2001, 11:24 AM
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-2&quot;>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;cs&quot;> Yes, I'm afraid I may have led you astray because as you have indicated these parameters are not passed to the server. <sorry> However, and you may want to test this, but I believe these values are &quot;sticky&quot;. Once you set your broser's encoding, it will stay that way for that browser session until you change it again.

Rich
[This message has been edited by Rich (edited 04-12-01@10:24 am)]