Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i would like to make folders for its own languages.

as an example i have the file foo.php. that file has a english version and a dutch version also.

therefor i created the directories /english/foo.php and /dutch/foo.php both files in that directories will be exactly the same as in the root folder.

in the root folder root/foo.php i load a variable $var that comes from an other file and directory that is called root/scripts/bar.php

in the file root/scripts/bar.php i do use a header function:

if ($pref_language == 'zu'){
    $header = 'english'.$_SERVER['PHP_SELF']; 
    $var = "xyz";  
}

header ("location: $header");

the problem is that when i will open root/foo.php the header function works as it should be but $var wont be initialised on that headered direction. when i will open source code there is nothing for

<?php echo $var;?>

but when looking at the source code without headering the variable will be loaded.

so this is a little bit strange to me. if there is someone who could help me out i really appreciate.

thanks alot.

share|improve this question
 
I hope you didn't put business logic on foo.php –  shiplu.mokadd.im Dec 12 '12 at 23:58
 
what does that mean? –  bonny Dec 12 '12 at 23:59
 
Did you put business/application logic on foo.php? –  shiplu.mokadd.im Dec 13 '12 at 0:05
 
what do you mean with business logic? –  bonny Dec 13 '12 at 0:08
 
show 1 more comment

2 Answers

Using header("location: $header"); redirects the browser to $header, this is not what you want.

You could include($header); (documented here or more probably require documented here) which would then allow the file in $header to use the variables defined.

What seems like you really want to do is internationalization, and there are good tools to do that in PHP such as Twig (here) or Smarty (here)

share|improve this answer
add comment

Your best best might be to utilize rewrite rules in your webserver to direct URL requests for certain languages to a parameter that can be used by the php file. An example in Apache might look like this:

RewriteEngine On
RewriteRule ^/?(english|dutch)/(.*)$ /$2?lang=$1 [L,QSA]

The would for example cause requests to /english/foo.php to be passed to /foo.php?lang=english for processing.

You could then look at $_GET['lang'] to determine which localization to use.

This eliminates the need to do any browser redirects, and gives you a nice way to dynamically prepend the $_GET['lang'] value to all links within your site to give the appearance to teh end user that they are completely within the English site (/english/*) or the Dutch site (/dutch/*).

share|improve this answer
 
hello, i use http_accept_language to get the information that i need. so using htaccess is not an option for me. –  bonny Dec 13 '12 at 0:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.