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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:56:15+00:00 2026-06-09T21:56:15+00:00

I’m building a website that has dual languages with two flags as an entry

  • 0

I’m building a website that has dual languages with two flags as an entry page. I’m planning on using <form method="post"> around the flags so the user can select the language they want.

Then on the following pages I want to use something like:

<?php
if( $_POST['language']=='uk' ){
    echo $uk;
}elseif( $_POST['language']=='french' ){
    echo $french;}
?>

So on clicking the flag, they have selected the language they want. Will that only work on the next page after they have clicked the flag or can they carry on navigating to different pages and it still pick up what language was selected?

If that doesn’t work, how else can it be done?


UPDATE:

I don’t think I made it clear before that I’m using WordPress, which apparently doesn’t like $_SESSION.

I have this on a template called region.php to submit the language selection:

    <form action="<?php the_permalink(); ?>/home" name="region" method="post">              
        <div id="uk">
            <a href="javascript:document.region.submit()" name="UK">
                <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/-uk.png" width="259" height="160" alt="UK" />
            </a>
            <h1 style="color:black!IMPORTANT;">Enter United Kingdom site</h1>
        </div>

        <div id="world">
            <a href="javascript:document.region.submit()" name="World">
                <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/
world.png" width="258" height="160" alt="
Rest of the World" />
            </a>
            <h1 style="color:black!IMPORTANT;">Enter Rest of the World site</h1>                    
            </div>  
    </form>

What do I need to put on every other template to check what language was selected? To help with the example if UK has been selected then it can just echo “UK”, if the rest of the world was selected then it can just show “World”.

This needs to work across several pages so if they goto the about page it checks the language, then if they navigate to the contact page it checks the language again – all that has to come from the initial language selection.

  • 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-09T21:56:16+00:00Added an answer on June 9, 2026 at 9:56 pm

    Answers

    Firstly, for adding regional / multilingual support to a wordpress site there is no better alternative than this plugin: http://wpml.org/. It has a cost associated with it, but its not prohibitive (you pay for awesome support).

    Secondly, You cannot use $_SESSION by default. WP is stateless by design. That said there are tons of plugins and tutorials online for getting this functionality.

    Code stuff

    Your original form html had no inputs. It was a form that submitted nothing. This form has two submits named the same thing location. So whichever button is clicked will submit its value against the $_POST['location'].

    <form action="<?php the_permalink(); ?>/home" name="region" method="post">              
        <div id="uk">
            <input type="submit" name="location" value="UK" />
            <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/uk.png" width="259" height="160" alt="UK" />
            <h1 style="color:black!IMPORTANT;">Enter United Kingdom site</h1>
        </div>
    
        <div id="world">
            <input type="submit" name="location" value="World" />
            <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/world.png" width="258" height="160" alt="Rest of the World" />
            <h1 style="color:black!IMPORTANT;">Enter Rest of the World site</h1>                    
        </div>  
    </form>
    

    Write a wordpress action to handle the post. Add this to your theme’s functions file.
    look at http://php.net/manual/en/function.setcookie.php for setcookie docs.

    function set_location_cookie()
    {
        if(isset($_POST['location']))
        {
            setcookie('location', $_POST['location'], time()+1209600);
        }
    }
    add_action('init', 'set_location_cookie');
    

    Then, anywhere you want to know the location:

    <?php echo $_COOKIE["location"]; ?>
    

    ADDITIONAL INFO

    I initially clicked UK to start with and this set the cookie, I then went back and clicked World but that didn’t copy over the cookie with world, it just showed UK again. Is it possible to wipe over the cookie each time a different selection is made?

    So this is an issue regarding how cookies work at a technical level:

    When the browser does this [requests a site], it will look on your machine for a cookie file that [your site] has set. If it finds a cookie file, your browser will send all of the name-value pairs in the file to [the] server along with the URL. If it finds no cookie file, it will send no cookie data.

    The new cookie data is not initially sent, b/c it inst until after the request has been sent from your browser to the server that the new cookie data is saved and available for sending with the request.

    How do you make this work then?
    redirect after a successful set cookie event.

    function set_location_cookie()
    {
        if(isset($_POST['location']))
        {
            // Set Cookie
            setcookie('location', $_POST['location'], time()+1209600);
            // Reload the current page so that the cookie is sent with the request
            header('Location: '.$_SERVER['REQUEST_URI']);
        }
    }
    add_action('init', 'set_location_cookie');
    

    Also is it possible to use the images of the flags as the submit buttons?
    Yes, use CSS to style your input buttons.

    Add an id to each input: id="uk-button" and id="world-button"

    CSS:

    #uk-button {
        background-image: url(uk-flag.png);
        background-size: 100%;
        background-repeat:no-repeat;
    }
    #world-button {
        background-image: url(world-flag.png);
        background-size: 100%;
        background-repeat:no-repeat;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.