Jump to content

Dynamic Links + Multi Language


XRS

Recommended Posts

Hello,

 

At my free time I just want to play with PHP and I'm trying to assume a website with dynamic links and multi language at the same time.

I use $_GET to get the language and the page that user wants to load, but I have some problems. The first run doesn't work. After define the language and page it works perfectly.

 

If you could, please see the code I used in the files attached

Multi-Language - header.php - Between ln4 and 43. The example links lines 74,75,83,84

Dynamic Links - index.php - Between line 5 and 17

 

 

Could you please help me in this way?

Thanks in advance.

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/240011-dynamic-links-multi-language/
Share on other sites

As I can't edit the thread, here is the code:

 

index.php page ( dynamic links )

 

$page = (isset($_GET['p']) === TRUE? strtolower($_GET['p']) : '');

switch($page){
case 'music':
include("pages/music.php");
break;

default:
include("pages/main.php");
break;
}

 

 

header.php ( Multi Language)

session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_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 'pt':
  $lang_file = 'lang.pt.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;

 

Example Links ( Langue Choose: )

 

        <a href="index.php?p=<?php echo $_GET['p']; ?>&lang=uk"><img src="images/uk.png" /></a>
        <a href="index.php?p=<?php echo $_GET['p']; ?>&lang=pt"><img src="images/pt.png" /> </a>

 

Example Links ( Page Choose: )

 

          <li><a href="index.php?p=main&lang=<?php echo $_GET['lang']; ?>"><?php echo $lang['MENU_HOME'];?></a></li>
          <li><a href="index.php?p=music&lang=<?php echo $_GET['lang']; ?>"><?php echo $lang['MENU_MUSIC'];?></a></li>

 

 

Hope this can help :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.