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

  • Home
  • SEARCH
  • 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 638665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:45:26+00:00 2026-05-13T20:45:26+00:00

I change the language in my site using PHP arrays and lang?= . When

  • 0

I change the language in my site using PHP arrays and lang?=. When the user clicks a link to change the language of the site I want this link to keep “pressed” or change to a different color, so the user knows in which version of the site he/she is. How can I activate a CSS property in this situation?

common.php:

    <?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;
?>

lang.en.php:

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

index.php:

<ul id="lang">
    <li><a href="index.php?lang=en">English</a></li>
    <li><a href="index.php?lang=es">Español</a></li>
    <li><a href="index.php?lang=tw">中文(繁體)</a></li>
    <li><a href="index.php?lang=cn">中文(简体)</a></li>
</ul>
  • 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-13T20:45:27+00:00Added an answer on May 13, 2026 at 8:45 pm

    You could test the value of $lang in the portion of code that generates the HTML output, and add a CSS-class on the link which corresponds to that language :

    <ul id="lang">
        <li><a href="index.php?lang=en" <?php if($lang=='en') {echo 'class="current_language"';} ?>>English</a></li>
        <li><a href="index.php?lang=es" <?php if($lang=='es') {echo 'class="current_language"';} ?>>Español</a></li>
        <li><a href="index.php?lang=tw" <?php if($lang=='tw') {echo 'class="current_language"';} ?>>中文(繁體)</a></li>
        <li><a href="index.php?lang=cn" <?php if($lang=='cn') {echo 'class="current_language"';} ?>>中文(简体)</a></li>
    </ul>
    

    Depending on the value of $lang, one of the four links would have the CSS class current_language. Up to you to set it in your CSS file so it highlights the link which has it.

    The generated HTML will then look like this (when $lang is 'en') :

    <ul id="lang">
        <li><a href="index.php?lang=en" class="current_language">English</a></li>
        <li><a href="index.php?lang=es" >Español</a></li>
        <li><a href="index.php?lang=tw" >中文(繁體)</a></li>
        <li><a href="index.php?lang=cn" >中文(简体)</a></li>
    </ul>
    

    (Of course, you’ll have to make sure the $lang variable is visible from the portion of code that generates the HTML output)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to permanently change variables in a php file using
I am a PHP Developer and Recently I develop a web site using PHP
I'm using Google Translate's dropdown menu to translate a site, but this doesn't persist
My web-application project (not web-site project) is translated to 15 different languages using the
given this example found on JSON site, in my case i'm using an API
Is it possible to change the font size used in a ContextMenu using the
i looking for help... and hope of you kindly I want to change my
I want to conform my site's string handling to support other languages per UTF-8.
I'm starting a new site project in Codeigniter. I need this site to be
I am building my first ASP.NET MVC site and this site needs to be

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.