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
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 :)

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.