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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:45:58+00:00 2026-05-22T18:45:58+00:00

I’m helping put together a site that’s going to host content for different regions

  • 0

I’m helping put together a site that’s going to host content for different regions on the same domain. So example:

http://www.example.com/us/
http://www.example.com/uk/
http://www.example.com/fr/
etc.

I have a system in place that asks the user which site they want to view (and then stores their preference in a cookie). My question is: If they visit a URL (e.g.: http://www.example.com/us/contact.php) and their preference cookie says /fr/, how do I best forward them to http://www.example.com/fr/contact.php?

The system can read what site region they’re on and what their cookie says. So the information we would know would be: Site: US and Cookie: FR.

I was thinking of using $_SERVER['SCRIPT_NAME'] and using regex to get “contact.php” from the URL. Then using header("Location: [url]");, but I understand that Location doesn’t work if any text has already been passed to the browser… which creates all sorts of problems.

Edit:
Here’s some code to explain the problem more clearly:

<?php
// Get variable contents for $cookieRegion and $siteRegion
if($cookieRegion != '') { // If Cookie has been previous set
    if($cookieRegion != $siteRegion) { // If Cookie pref clashes with site URL
       // Forward to correct URL
    }
}
else { ?>
    <script type="text/javascript">
        $(document).ready(function(){
            // Display modal window asking user preference
        });
    </script>        
<?php } ?>

So the <script> tag would be placed before the document start… not a good idea!

What’s the best way to get around this problem?

Or, is there a better way of handling the whole problem that I could implement instead?

  • 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-22T18:45:59+00:00Added an answer on May 22, 2026 at 6:45 pm
    <?php
    // Use this to open modal window.
    $wrongRegion = FALSE;
    
    // if there is a cookie...
    if (isset($_COOKIE['region']))
    {
        // I am using preg_match to ensure we are getting right parameters...
        // Sorry I am not good with Regex. You can set a better patern.
        preg_match("#/(.*?)/(.*?)\.php#is", $_SERVER['REQUEST_URI'], $m);
    
        // Okay! $m[1][0] is the region code on the uri. lets check if its same with cookie
        if ($_COOKIE['region'] != $m[1][0])
            $wrongRegion = TRUE;
    }
    
    ....... (codes goes here)
    
    // to where you put the modal window code:
    
    if ($wrongRegion == TRUE)
    {
        // put the modal window code.
    }
    

    so you can add a check to preg_match. It prevents to execute rest of the code.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string

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.