Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 611063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:44:35+00:00 2026-05-13T17:44:35+00:00

The code works when I declare $lang like this (at the top of the

  • 0

The code works when I declare $lang like this (at the top of the index file):

index.php (with php variable declaration at the top):

   <?php
        $lang = 'es';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
        <title>New Project</title>
        <link rel="stylesheet" type="text/css" href="styles/global.css" />
    </head>
    <body id="home">
    <div id="header">
        <div class="container">
            <div id="header-top">
                <h1><a href="http://widerdesign.co.nr/">wider design</a></h1>
                <ul id="lang">
                    <li><a href="index.php?lang=en" <?php if($lang=='en') {echo 'class="current"';} ?>>English</a></li>
                    <li><a href="index.php?lang=es" <?php if($lang=='es') {echo 'class="current"';} ?>>Español</a></li>
                    <li><a href="index.php?lang=tw" <?php if($lang=='tw') {echo 'class="current"';} ?>>中文(繁體)</a></li>
                    <li><a href="index.php?lang=cn" <?php if($lang=='cn') {echo 'class="current"';} ?>>中文(简体)</a></li>
                </ul>

but it doesn’t work when its declared in a included file:

index.php (with included file which has the php variable declaration):

<?php
include_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>New Project</title>
    <link rel="stylesheet" type="text/css" href="styles/global.css" />
</head>
<body id="home">
<div id="header">
    <div class="container">
        <div id="header-top">
            <h1><a href="http://widerdesign.co.nr/">wider design</a></h1>
            <ul id="lang">
                <li><a href="index.php?lang=en" <?php if($lang=='en') {echo 'class="current"';} ?>>English</a></li>
                <li><a href="index.php?lang=es" <?php if($lang=='es') {echo 'class="current"';} ?>>Español</a></li>
                <li><a href="index.php?lang=tw" <?php if($lang=='tw') {echo 'class="current"';} ?>>中文(繁體)</a></li>
                <li><a href="index.php?lang=cn" <?php if($lang=='cn') {echo 'class="current"';} ?>>中文(简体)</a></li>
            </ul>

common.php:

session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang'])) {
    $lang = $_GET['lang'];    
    // register the session and set the cookie
    $_SESSION['lang'] = $lang;    
    setcookie("lang", $lang, time() + (3600 * 24 * 30));
} else if(isSet($_SESSION['lang'])) {
    $lang = $_SESSION['lang'];
} else if(isSet($_COOKIE['lang'])) {
    $lang = $_COOKIE['lang'];
} else {
    $lang = 'en';
}

switch ($lang) {
  case 'en':
      $lang_file = 'lang.en.php';
      break;    
  case 'es':
      $lang_file = 'lang.es.php';
      break;    
  case 'tw':
      $lang_file = 'lang.tw.php';
      break;    
  case 'cn':
      $lang_file = 'lang.cn.php';
      break;    
  default:
      $lang_file = 'lang.en.php';    
}    
include_once 'languages/'.$lang_file;

Is $lang really having any value when its declared in the common.php file?

edit: the language change in the file is working is just the class .current not being activated, weird.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:44:35+00:00Added an answer on May 13, 2026 at 5:44 pm

    The $lang variable is set at the top of your common.php file ; and you are then trying to use it from the content of index.php.

    But, between the top of common.php and the content of index.php, you are including the languages/lang.XX.php file.

    Are you sure there is not something, in that lang.XX.php file, that overrides the content of the $lang variable ?

    Judging from this other question (To which I answered, and this question here seems like a follow-up of that question there — I didn’t really notice that the $lang variable was being overriden), lang.en.php contains this :

    <?php
    $lang = array(
        'h1' => 'Hello World',
    );
    ?>
    

    Which overrides the $lang variable :

    • in common.php it is used to store the language code
    • in lang.en.php is it overriden, set to an array of string
    • which means that, later, in index.php, it cannot be equal to the language code — and the condition to set the CSS class fails.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a beginner question. This is a piece of code that works: declare @RowNr
This code works in IDLE but not in the commandline. Why the difference? poem
// following code works fine n open notepad... class demo { public static void
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code works fine: $result = $client->__call(optionalInfo, array( new SoapParam(..., client), new SoapParam(..., add_code))
This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would
This code works: monkey.h @interface monkey : NSObject { NSNumber *monkeyRanch; } @property (nonatomic,
This code works (when ControlType=dropDown then the background yellow ): <Window x:Class=TestCollapsed.Views.MainView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works, but is inefficient because it double-lookups the ignored dictionary. How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.