I help to build a website that will host content for different regions in the same domain. So an example:
www.example.com/us/
www.example.com/uk/
www.example.com/fr/
et al.
I have a system that asks the user which site they want to view (and then saves their preferences in a cookie). My question is: if they visit the URL (for example: www.example.com/us/contact.php) and their cookie preference says / fr /, how should I send them to www.example.com/fr/contact . Php?
The system can read what area of the site they are in and what their cookie says. So the information we would know would be: Site: USA and Cookie: FR.
I thought to use $_SERVER['SCRIPT_NAME']and use regex to get "contact.php" from the url. Then, using header("Location: [url]");, but I understand that it Locationdoesn’t work if any text is already transferred to the browser ... which creates all kinds of problems.
Edit:
Here are a few examples to more clearly explain the problem:
<?php
if($cookieRegion != '') {
if($cookieRegion != $siteRegion) {
}
}
else { ?>
<script type="text/javascript">
$(document).ready(function(){
});
</script>
<?php } ?>
So, the tag <script>will be placed before the start of the document ... not a good idea!
What is the best way to get around this?
Or is there a better way to handle the whole problem that I could implement instead?
source
share