Click here to Skip to main content
16,017,650 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

What i want to ask if it is possible not to redirect user to the home page everytime -after he change language (French or German)- but to let him be in the page he is currently is, with the change in language.

The below is my code. Dont know wt to add extra. Bit new to PHP. Please help.

PHP
<?php
session_start();
header('Cache-control: private'); 
if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

$_SESSION['lang'] = $lang;
setcookie('lang', $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}
switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;
  case 'fr':
  $lang_file = 'lang.fr.php';
  break;
  case 'de':
  $lang_file = 'lang.de.php';
  break;
  default:
  $lang_file = 'lang.en.php';
}
include_once 'languages/'.$lang_file;

?>
Posted

1 solution

The code you are showing has nothing to do with your question. And your question has more to do with HTML.

When you are using an input element (html) then the form action defines where to go. You don't have to return to the home page.
HTML
<form name="input" action="homepage.php" method="get"></form>

You can skip (or leave blank) the action attribute to redirect to the current page. With PHP you can determine what html input control submitted the form and you can use that to do something, like redirecting to other pages.

You can also use links with an image:
<a href="http://www.yoursite.com/currpage.php?lang=en">
 <img src="lang_en.png" />
</a>

Get the 'lang' parameter to update the language.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900