Hi i have scripts that redirect page for language settings thanks the guy who helped me sorted out my first problem now i am facing another problem there is a script working in www.server.com if you type only www.server.com now i created function and if you type www.server.com?redir=1 this function will not work and site will come but then my script doesnt work with ?redir=1 i think only solition have some cookie or session if someone type www.server.com?redir=1 everytime it checks and if redir ok directly goes to www.server.com without problem this problem i face because for example if you are from italy and want to see server.com you can't because server directly send you server.it all the time i put the link like www.server.com?redir=1 to disable redirect function page is okay but script not working due to address.

<?php
function redirect()
{
$Destination['en-au'] = 'http://www.server.com.au';
$Destination['pl'] = 'http://www.server.pl';
$Destination['it'] = 'http://www.server.it';

$lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$lang = preg_replace('/,.*$/','',strtolower($lang));
$dest = '';
if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
if( empty($dest) )
{
   $lang = substr($lang,0,2);
   if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
   else { $dest = $DefaultDestination; }
}
if( ! empty($dest) )
{
   header("Location: $dest");
   exit;
}
}

if (!isset($_GET['redir'])) redirect(); // if www.server.com/?redir=1 run this func. i dont want /?redir=1  


....
....
....
....


?>

Recommended Answers

All 8 Replies

it should surely be

function redirect($Destination)

so that the function knows what the destination is. You would therefore need to change the code in the main body to

if (!isset($_GET['redir'])) redirect($variablewhichholdsthedestination); // if

i think there is small misunderstanding situation this code already working in server.com i meant defaultdestionation is www.server.com all trafic comes from countries like server.it or server.pl all i want is when you type www.server.com/?redir=1 it ll understand you wanna see www.server.com and it'll disable function then itll remove /?redir=1 keeps in mind that function is disabled then script goes www.server.com will open instead www.server.it

i done the code you provided me but nothing change /?redir=1 still upthere

<?php
      function redirect($destination)
      {
      $Destination['en-au'] = 'http://www.server.com.au';
      $Destination['pl'] = 'http://www.server.pl';
      $Destination['it'] = 'http://www.server.it';
        $DefaultDestination = 'http://www.server.com';  //this is where i want to achive
       $lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
      $lang = preg_replace('/,.*$/','',strtolower($lang));
        $dest = '';
        if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
        if( empty($dest) )
        {
        $lang = substr($lang,0,2);
        if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
        else { $dest = $DefaultDestination; }
        }
        if( ! empty($dest) )
        {
        header("Location: $dest");
        exit;
       }
      }
  
     if (!isset($_GET['redir'])) redirect($defaultdestionation); 
  
      ....
      ....
      ....
      ....
      ?>

I don't use the syntax you have on line 25, but if it's correct, it should work ok. In case it's not, you could change it to:

if (!isset($_GET['redir'])) { 
redirect();
}

Other than that, it looks ok... If it still doesn't work, come back

Hi i got some error when i use this code

Warning: Missing argument 1 for redirect(), called in /home/servcom/public_html/index.php on line 25 and defined in /home/servcom/public_html/index.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/servcom/public_html/index.php:2) in /home/servcom/public_html/index.php on line 25

<?php
function redirect($destination)
{
$Destination['en-au'] = 'http://www.server.com.au';
$Destination['pl'] = 'http://www.server.pl';
$Destination['it'] = 'http://www.server.it';
$DefaultDestination = 'http://www.server.com'; //this is where i want to achive
$lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$lang = preg_replace('/,.*$/','',strtolower($lang));
$dest = '';
if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
if( empty($dest) )
{
$lang = substr($lang,0,2);
if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
else { $dest = $DefaultDestination; }
}
if( ! empty($dest) )
{
header("Location: $dest");
exit;
}
}

if (!isset($_GET['redir'])) {
 redirect();
 }
....
....
....
....
?>

Warning: Missing argument 1 for redirect(), called in /home/servcom/public_html/index.php on line 25 and defined in /home/servcom/public_html/index.php on line 2

put the function name (line 1) back to:

function redirect()

Warning: Cannot modify header information - headers already sent by (output started at /home/servcom/public_html/index.php:2) in /home/servcom/public_html/index.php on line 25

There can be no html output (even a space) before you use the header() command.

www.server.com/?redir=1
FIREFOX ERROR: The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

<?php
 function redirect()
  {
  $Destination['it'] = 'http://www.SERVER.it';
  $DefaultDestination = 'http://www.SERVER.COM'; //this is where i want to achive
  $lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  $lang = preg_replace('/,.*$/','',strtolower($lang));
  $dest = '';
  if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
  if( empty($dest) )
  {
  $lang = substr($lang,0,2);
  if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; }
  else { $dest = $DefaultDestination; }
  }
  if( ! empty($dest) )
  {
 header("Location: $dest");
 exit;
 }
 }
if (!isset($_GET['redir'])) 
{ redirect();
}

check your .htaccess - looks as if the redirect is going to a page that redirects back here and so on

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.