Page 1 of 1

Page loads only after refresh Options

Posted: Sat Apr 22, 2006 12:49 pm
by Apyvala
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

i have a website on three speeches - Lithuania ( lt ), English ( en ) and Russian ( ru ). Website on one server works perfect, but on another server not.

In index file i have such code:

Code: Select all

if (!session_is_registered("speech")) {
if ($_SESSION['speech'] == "") {
session_register("speech");
$_SESSION['speech'] = "lt";
}
that is, default speech is lt. Moreower i have three links:

Code: Select all

<a href="change_speech.php?speech=lt" class="speech">LT</a> <a href="change_speech.php?speech=en" class="speech">EN</a> <a href="change_speech.php?speech=ru" class="speech">RU</a>
My change_speech.php file looks:

Code: Select all

<?php
session_start();

$_SESSION['speech'] = $_GET['speech'];

header ("Location: index.php");
?>

The problem: when i push on links "LT", "EN" or "RU" i see white page, i need to push F5 ( to refresh page ) than i could see the page.
This problem occurs only on one server, on another server i haven't such problem.

Any ideas?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Apr 22, 2006 12:51 pm
by timvw
Before you issue a header('Location: absoluteURL') you have to call session_write_close to make sure everything is saved.. (i said absoluteURL because i've found that relatie URL is not supported by all browsers)

Posted: Sun Apr 23, 2006 8:26 am
by Apyvala
Thank you for suggestion. But my website doesn't work well after the you suggested changes.

I has perceived an interesting thing. I am using:

HTML code:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


then i change it to:

<meta http-equiv="Content-Type" content="text/html; charset=win-1257" />


Than the website works well. Hmmm... it is very interesting for me.

win-1257 - Lithuanian encoding

Posted: Sun Apr 23, 2006 8:35 am
by timvw
Btw, i forgot to mention last time.. If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). (http://www.php.net/session_is_registered)

Change your index.php to something like:

Code: Select all

// start a the session only if it's not started already
if (!isset($_SESSION)) {
 session_start();
}

// assign default value if value isn't set yet
if (!isset($_SESSION['speech'])) {
 $_SESSION['speech'] = 'lt';
}

Posted: Mon Apr 24, 2006 6:32 am
by Apyvala
Thank you very much for much for help.
My page works perfect when i replace:

session_start();

to

if (!isset($_SESSION)) {
session_start();
}

Posted: Mon Apr 24, 2006 7:34 am
by JayBird
Moved to PHP - Code

Posted: Mon Apr 24, 2006 2:09 pm
by timvw
Apyvala wrote:Thank you very much for much for help.
My page works perfect when i replace:

session_start();

to

if (!isset($_SESSION)) {
session_start();
}
Here's why:

You can call session_start only once... Otherwise an error/warning is generated...
As long as you don't call session_start, $_SESSION is not set (and thus session_start has not been called before).