Jump to content

going crazy over language switch


rilana

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.