views:

334

answers:

3

Hello, i'm trying to make my site with a few languages. Every page includes config-file, wich checks variable 'lang' in session. If it doesn't exist, wi'll be redirected to the page of lang choosing. After choosing u'll come to the page before. But it works only in Mozilla Firefox. In other browser after language checking i always get this page (lang checking). What i did wrong? Config-file:

// Here is session start...
if (!isset($_SESSION['site_lang']))
{
  $_SESSION['page_refer'] = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; 
  echo '<meta http-equiv="Refresh" content="0; URL=lang_choose.php">';
  exit;
}
else
{
  require_once 'languages/'.$lang.'.php';
}
?>

lang_choose.php:

// Session start
  @extract($_POST);
  if (isset($_POST['lang']))
  {
    $lang = $_POST['lang']; $lang = replace($lang);
    $_SESSION['site_lang'] = $lang;
    echo '<meta http-equiv="Refresh" content="0; URL='.$_SESSION['page_refer'].'">';
  }
  else
  {
      // Showing form with flags... which returns var 'lang'
  }


EDIT: If there is

< input type="image" src="img/langs/en.png" width="290" height="200" border="1" name="lang" value="en" />

in form it doesn't work in another browsers (except mozilla) but if i use:

< input type="submit" name="lang" value="en" />

Everything is good. Any ideas?

Thanks.

+6  A: 

Try using this to perform the redirect:

<?php
header('HTTP/1.1 302 Found');
header('Location: ' . $_SESSION['page_refer']);
// And just in case that doesn't work
echo '<html>',
     '<head>',
     '<title>Redirect</title>',
     '</head>',
     '<body>',
     '<script type="text/javascript">',
     'window.location.href = "' . $_SESSION['page_refer'] . '";',
     '</script>',
     '<a href="' . $_SESSION['page_refer'] . '">Click here to continue</a>',
     '</body>',
     '</html>';
?>

Also note that use of the <meta> tag to redirect is discouraged by the W3C.

Bravery Onions
it doesn't help =(
Ockonal
I made some changes. Now it will also give a 302 header, then try to redirect using JavaScript, and finally display a link. If that doesn't work, maybe you should check your PHP error log, or add `ini_set('display_errors', 'On');` to the top of the file. Note that `ini_set()` will only work if there are no parsing errors.
Bravery Onions
A: 

Try a javascript redirect if setting the location header doesn't work:

echo '<script>window.location.href="',$_SESSION['page_refer'],'"</script>';
Shadow
See edit, please.
Ockonal
A: 

If you do use header('location:'); based redirects make sure you add an exit() or die() afterwards, as the program will carry on running to the end, and some browsers may not even accept it, so it can fatally compromise security on occasions.

Meep3D