Jump to content

Recommended Posts

Hi there,

 

I created a bilingual site and connect two different language tables by two language session variables. However, when a language sesssion is created, population of data is being delayed. Basically, I have to refresh my web browser a couple of times manually in order to see the change of the language. Please see my code below and tell me if this can be fixed. Thanks very much in advance!!!

 

// Trigger language sessions

<?

if (isset ($_SESSION["lang"]))

{

if ($_SESSION['lang'] == "en")

{

echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=fr>Francais</a>';

}

else

{

echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=en>English</a>';

}

}

?>

 

// Create sessions

<?

session_start();

 

$lg = $_GET['lang'];

 

if (!isset($_SESSION["lang"]))

{

$_SESSION['lang'] = "en";

if ($lg=="en")

{

$_SESSION['lang'] = $lg;

}

if ($lg=="fr")

{

$_SESSION['lang'] = $lg;

}

}

else

{

if ($_SESSION["lang"] == "en" && $lg == "fr")

{

session_destroy();

$_SESSION["lang"] = $lg;

}

if ($_SESSION["lang"] == "fr" && $lg == "en")

{

session_destroy();

$_SESSION["lang"] = $lg;

}

}

?>

 

// Connect two language tables by session variable

<?

session_start();

  $conn = db_connect();

if (isset ($_SESSION["lang"]))

{

if ($_SESSION['lang'] == "en")

{

$query = "select * from tbl_page_en where qs = '$qs'";

}

if ($_SESSION['lang'] == "fr")

{

$query = "select * from tbl_page_fr where qs = '$qs'";

}

}

  else

  {

  $query = "select * from tbl_page_en where qs = '$qs'";

  }

?>

Link to comment
https://forums.phpfreaks.com/topic/89293-database-delay-with-session-variables/
Share on other sites

Try changing this code:

 

<?
if (isset ($_SESSION["lang"]))
{
   if ($_SESSION['lang'] == "en")
      {
         echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=fr>Francais[/url]';            
      }
   else
      {
         echo '<a href='.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&lang=en>English[/url]';
      }
   }
?>

 

To this:

 

<?
    if (isset ($_SESSION['lang']))
    {
        header("Location: " . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'] . "&lang=" . $_SESSION['lang']);
    }
?>

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.