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? Link to comment https://forums.phpfreaks.com/topic/81674-going-crazy-over-language-switch/ 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/ ?> Link to comment https://forums.phpfreaks.com/topic/81674-going-crazy-over-language-switch/#findComment-414894 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 Link to comment https://forums.phpfreaks.com/topic/81674-going-crazy-over-language-switch/#findComment-414952 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? Link to comment https://forums.phpfreaks.com/topic/81674-going-crazy-over-language-switch/#findComment-417053 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 ?> Link to comment https://forums.phpfreaks.com/topic/81674-going-crazy-over-language-switch/#findComment-417095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.