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 6667713
In Process

The Archive Base Latest Questions

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

I work with php5 and apache2 on my development machine. The production server is

  • 0

I work with php5 and apache2 on my development machine. The production server is apparently similar.

I have a script set_language.php that creates a session variable according to the language chosen:

<?php
session_start();
$back = $_SERVER['HTTP_REFERER'];

    if (isset($_GET['lang'])) {
            if ($_GET['lang'] == 'fr')
            $_SESSION['lang'] = 'fr';
        else if ($_GET['lang'] == 'en')
            $_SESSION['lang'] = 'en';
    }
    header( "Location: $back" ) ;
    exit();
?>

Then I include the code below on all pages:

session_start();
if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'en') {
    require('lang_en.php');
}
else if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'fr') {
require('lang_fr.php');
}

Than I can get language-dependent variables with:

echo $lang[sometexttotranslate];

On the development server it works as expected. I click on the link to set the language and my session variables contain lang=en or fr

On the production server:

$_SESSION[‘lang’] = dn or dr (should be en or fr)

echo $lang[sometexttotranslate] = d (should be a translated text)

Any idea where the “d”‘s come from?

This is not a redirection/header/session_start() problem.


print_r($_SESSION) on first load:

Array ( [lang] => fr )

print_r($_SESSION) after a click on the english link (set_lang.php above):

Array ( [lang] => dn )

print_r($_SESSION) after a click on the french link (set_lang.php above):

Array ( [lang] => dr )

print_r($_SESSION) after login:

Array ( [lang] => dr [valid] => 1 [pseudo] => GYC [uid] => 3 )

  • 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-26T02:57:45+00:00Added an answer on May 26, 2026 at 2:57 am

    Now this is something,

    print_r($_SESSION) after a click on the english link (set_lang.php above):
    
    Array ( [lang] => dn )
    

    your problem starts here in set_lang.php . Maybe a session is started from a file that is included and this should not happen!

    If set_lang is not included make sure a start_session exist there, also put a print_r there too, you could even compare the session ids too:

    let’s say this is index.php

    <?php
    session_start();  
    ?>
    <a href='set_lang.php?sess=<?PHP echo session_id();?>'>lang</a>
    

    and this set_lang.php

    <?PHP  
    session_start(); 
    echo 'this is session id from index.php: ',$_GET['sess'],
    'and this is session id in set_lang.php:',session_id(),
    'and this is the print_r:<br><pre>';
    print_r($_SESSION);
    ?>
    

    you should see the same session id.

    But while all these might help you I will take it a step further, use single entry point, do not call php script directly like this

    <a href=somescript.php>link</a>
    

    (unless you are doing some ajax) instead you always call some php script through index.php like this:

    <a href=index.php?target=somescript.php>link</a>
    

    This way you will have the session start placed only once in the index.php, the login check can be done in index.php too.

    =======================Edit More Info Added=========================================
    A fast google search.. found this small single entry tutorial http://www.renownedmedia.com/blog/php-navigation-system-using-single-entry-point/ there could be better ones.

    Even better it would be switching to an mvc framework (that includes the single entry point philosophy) but because the learning curve is more steep at least start with the single entry point.

    ============ReEdit more info added again==========================================
    A good option then would be to replicate this problem again but out of your project context, take as less as possible code from your project in new created files and try to create the problem again. keep it as simple as possible just try to create the error again

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

Sidebar

Related Questions

When I have this PHP script. <?php exec('/usr/local/bin/mate hello.txt'); ?> It doesn't work on
Ok, so I have this PHP script that runs in a nice little infinite
At work, we have multiple branches that we may be working on at any
I have a simple script that should cause one of three divs to be
I have added following lines into php.ini [XDebug] zend_extension = C:\PROGRA~1\PHP5\ext\php_xdebug-2.1.0-5.3-vc9.dll xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_host=localhost
I have WAMP SERVER,PHP 5.3.0 and Apache server 2.2.11 I want to download a
I am currently trying to get Xdebug to work on our development server. As
I have 2 web servers, Server A & Server B. Both running PHP5 +
work on asp.net vs 05 C#.Master page header contain the bellow code <script type=text/javascript
work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job

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.