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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:09:31+00:00 2026-06-16T17:09:31+00:00

I am making a site, using only PHP as back-end (no framework), which should

  • 0

I am making a site, using only PHP as back-end (no framework), which should be available in 3 languages. The site structure (tables/divs) is maybe less common. It tends to simulate an Ajax kinda behavior. I include a file (selector.php) in the body, which takes care of it’s content, via _GET(), passed from the navigation links. This means, that the site actually never leaves index.php. The languages are links (flags).

Now, I did managed to implement successfully the 3 languages (arrays/session/cookie), and it does work. However, what I need is to be able to make the language selection to stay/refresh the same page from where it was called. Here it becomes tricky, since I am using only one page, every include/subsequent includes (30+) are called from the index.php, so using the header ('Location: ...') seems not to be an option.
I know how to retrieve my current address, including the GET parameter, so I could use it. But how? Reading it at the beginning of the code, then re-read in the language module does match at any given point. There is a session, so I could also use session variables, but making 35+ variables for the content (so url changes) and match them all the time, does not seem to be the right method. Where, and more precisely how to catch the language change, and how to refresh/redirect to the “same page” for the changes to take effect? It could be a design flow.

Note 1: Using mod_rewrite I redirected my language query, so now instead of mysite.com/index.php?lang=en, it’s in form of mysite.com/en/index.php so I can use more friendly links to call the body content.
Note 2: I passed the last week reading/searching here/anywhere Google leads, trying countless times different approaches, none of them worked as expected (maybe concept flow?!).
Note 3: Since this is for a client, who explicitly asked not to use Java at all, please don’t give Ajax/jQuery/Java solutions (with those, I would know how to do).
Note 4: The whole code is rather large to paste here, so if you need to see different parts, name them, and I’ll edit my question.
Note 5: I still retain myself as a beginner, so please bear with me.

Thanks in advance.

So the language selector looks like that:

    session_start();
    header('Cache-control: private'); // IE 6 FIX
    if(isSet($_GET['lang'])) {
        $lang = $_GET['lang'];
        $_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 = 'ro'; }

    switch ($lang) {
    case 'en': $lang_file = 'lang.en.php'; break;
    case 'it': $lang_file = 'lang.it.php'; break;
    case 'ro': $lang_file = 'lang.ro.php'; break;
    default: $lang_file = 'lang.ro.php'; break; }

    include_once 'languages/'.$lang_file; 

Then the selector…

    function isValidPage($cont) {
     $validpages = array("history","mission","etc");
     if(in_array($cont,$validpages) && file_exists(ltrim($cont,'/') . '.php')) {
          return TRUE; } 
    else {
          return FALSE; }
    }

    if(isset($_GET['cont']) && isValidPage($_GET['cont'])) {
        @include($_GET['cont'] . '.php'); } 
    else {
        @include('sub_index.php'); }  

I start my index.php with:

      <?php include_once 'lang_sel.php'; ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>mysite</title>
    <link rel="stylesheet" href="style/css.css" type="text/css" />   

</head>
<body>
    <div class="parent">
        <div class="left"><?php include("main/left_main.php"); ?></div>
        <div class="right">
            <div class="topmain"><?php include("main/top_main.php"); ?></div>
            <div class="dummyx"></div> <!-- dummy div for adjusting starting position -->
            <div class="rightall">
                <?php include("main/top_nav.php"); ?>
                <?php /*include("main/top_rotator.php"); */?>
                <table width="780" border="0" cellpadding="10px" cellspacing="0" bgcolor="transparent" id="middle"><?php include ('selector.php'); ?></table> <!-- container for the main content -->
            </div>       
            <div class="footer">
                <?php include("main/bottom.php"); ?>
                <?php include("main/footer.php"); ?>
            </div>
        </div>
        <div class="clr"></div> <!-- clearing div attributes -->
    </div>  

Then the left side contains the flags:

<tr>
    <td width="30">&nbsp;  </td>
    <td width="63" align="center" valign="middle"><span class="lang"><a href="<?=WEBROOT?>ro/index.php" title="Romana"><img src="images/flags_ro.jpg" alt="ro" name="Romana" width="35" height="40" /></a></span></td>
    <td width="63" align="center" valign="middle"><span class="lang"><a href="<?=WEBROOT?>en/index.php" title="English"><img src="images/flags_en.jpg" alt="en" name="English" width="35" height="40" /></a></span></td>
    <td width="63" align="center" valign="middle"><span class="lang"><a href="<?=WEBROOT?>it/index.php" title="Italiano"><img src="images/flags_it.jpg" alt="it" name="Italiano" width="35" height="40" /></a></span></td>
    <td width="30">&nbsp;  </td>
</tr>

Also the menu, which is a bunch of lists like:

        <ul class="menu">   
            <li><a href="index.php?cont=history" style="background:none"><?php echo $lang['MENU_HISTORY']; ?></a><!--<div><span>if you want to add 'sub-content' put it here</span></div>!--></li>
            <li><a href="index.php?cont=mission" style="background:none"><?php echo $lang['MENU_MISSION']; ?></a></li>
            <li><a href="index.php?cont=p_systems" style="background:none"><?php echo $lang['MENU_P_SYSTEM']; ?></a></li>
            <li><a href="index.php?cont=s_dist" style="background:none"><?php echo $lang['MENU_S_DIST']; ?></a></li>
        </ul>

The content is simple, text and images. So the main code is above…

  • 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-06-16T17:09:32+00:00Added an answer on June 16, 2026 at 5:09 pm

    After 1 trillion trials/errors, I finally made it! Maybe it’s not the most elegant solution (ie. spartan), but it works. The catch was to read the current URL, explode it to get the current page with params, then put it in the href’s of the flags.

    So at the beginning of index.php I’ve put:

    <?php 
        $url = $_SERVER['REQUEST_URI']; 
        $pieces = explode("/", $url); 
    ?>
    

    Then my flag’s links became:

    <a href="<?=WEBROOT . 'en/' . $pieces[3]?>" title="English">
    

    where WEBROOT is my base url and folder, and $pieces[3] is always my current page (ie. index.php?cont=history. This way I always land on the current page, and the language is changed accordingly.

    Note: In my case. the 3rd piece contains the current page. If someone else use this technique, be sure to check that. Also, I’m using only 1 parameter all the time, so keep that in mind (tho it doesn’t actually matter).

    If someone else knows a better solution, I’m open minded. Thanks for everyone tho.

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

Sidebar

Related Questions

I was playing around making a simple haiku site using sqlalchemy and pylons. It
i'm working on a wordpress site using buddypress. So, i'm making a page where
I'm making a video sharing site just for learning and fun. I am using
I have a web-site based on PHP, to which I would like to add
im making a small site And Instead of having a header.php and a footer.php
I'm making a web call using the async framework. I'm getting an Error noted
My site will be using the APIs like Paypal and also making Facebook Apps.
I am making an ASP.NET MVC site which needs to serve a number of
I'm using following htaccess rule which is proposed all over internet for removing index.php
I am making a social website using Zend. The site allows users to become

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.