rilana Posted December 14, 2007 Share Posted December 14, 2007 I am trying to do a simple langauge switch and I thaught I had figure it out, but no it sitll doesnt work. <?php function sprache() { switch($_REQUEST['language']) { case 'english': header("Location: " . $_SERVER['DOCUMENT_ROOT'] . "/english/"); exit; break; case 'deutsch': header("Location: " . $_SERVER['DOCUMENT_ROOT'] . "/deutsch/"); exit; break; } } ?> Link to call the script <p><a href="?language=english">test</a></p> What is happening is that it does http://www.rilana.biz/geissmann/deutsch/test.php?language=english unstead of going http://www.rilana.biz/geissmann/english/test.php?language=english Please does anyone know why this is not working? Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 14, 2007 Share Posted December 14, 2007 first of all why is it in a function and not straight switch code? <?php //$language = $_GET['language']; $language = "english"; //for testing on my system without using the $_GET functions switch($language) { case "english": $address = "/english/"; break; case "deutsch": $address = "/deutsch/"; break; } $header = $_SERVER['DOCUMENT_ROOT']; $headerAddress = "$header$address"; echo $headerAddress; //for me echos C:/Program Files/xampp/htdocs/english/ ?> Quote Link to comment Share on other sites More sharing options...
rilana Posted December 14, 2007 Author Share Posted December 14, 2007 hi thanks for your replay when I do what you said I get /home/rilanab/public_html/deutsch/ as echo. But how do I make the link? How do I say show the same documentname from the english folder? I tryed <a href="?language=english">test</a> but that links me to http://www.rilana.biz/geissmann/deutsch/test.php?language=english unstead of http://www.rilana.biz/geissmann/english/test.php Quote Link to comment Share on other sites More sharing options...
rilana Posted December 17, 2007 Author Share Posted December 17, 2007 Hi guyes beleve it or not I am still trying to do this language switch thing and it is realy giving me such a hard time! I realy would aprechiate it if someone could stick with me and help me thrue it! I tryed to figure it out and tryed so many different ways but it just want work for me! I find it verry confusing!!!! Please help me! I ended up trying to do this! <?php switch($language) { case "english": $address = "/english/"; $header = $_SERVER['SCRIPT_NAME']; $headerAddress = "$header$address"; header("Location: $headerAddress"); break; } ?> and then call it with <a href="?language=english">test</a> but that does not work at all! Does anyone has a good Idea? Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 17, 2007 Share Posted December 17, 2007 try this <?php $language = "deutsch"; //set it here, you set it by $_GET $url = "http://www.rilana.biz/geissmann/test.php?language=english"; //you set this by $_SERVER['DOCUMENT_ROOT']; switch($language) { case "english": $address = "english/"; break; case "deutsch": $address = "deutsch/"; break; } $keywords = preg_split('/\//', $url, -1, PREG_SPLIT_OFFSET_CAPTURE); //creates an associative array splitting by "/" $count = count($keywords)-1; //find the number of the last entry in the array $num = $keywords[$count][1]; //get the offset number of the letter of the last "/" $first = substr($url,0,$num); //split the address up to that character number $second = substr($url,$num); // and after that character number $header = "$first$address$second"; //create the new address with the english / deutsch in the right place echo $header; //echo it out to have a look ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.