Jump to content

davvid

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

davvid's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. When the link is generated it points to page.pl.php When I view the generated source the link in menu shows the variable page.php?lang=pl but after clicking the link I'm ending up with page.pl.php in the address bar.
  2. hey guys, I'm in the process of transforming my static html website into "something" more dynamic. I came across an article on bilingual website (http://www.jacksonengineering.net/proj_phplanguage.php) and I basically used the same idea for my project. Everything works fine except for one thing - links to different language web pages are generated correctly page.php?lang=pl but when I click on the link, the url loses the variable and looks like page.pl.php What to do? language.php <?php //the url ? language declaration should have preference over the page name $pagename = basename($_SERVER['PHP_SELF'],".php"); $pagenamearray = explode(".",$pagename); if (count($pagenamearray) == 2){ //there is currently a bi-lingual site page loaded $_SESSION['language'] = $pagenamearray[1]; $urllang = $pagenamearray[1]; }else{ //this page must be a non bi-lingual page $urllang = 'en'; } //check for a language selection on the url if(isset($_GET["lang"])){//language has been passed via url $_SESSION['language'] = htmlspecialchars($_GET["lang"]); //set it what was found } ///if there still is no language set, go with english for a default if(!isset($_SESSION['language'])){ $_SESSION['language'] = 'en'; } //now we think we have the session language figured out // //now check for a version of the current page in the desired language //lets make some things clear first //the current page url is either en or pl from $urllang if($urllang != $_SESSION['language']){ //if the url isn't the same as the $_SESSION if($_SESSION['language'] == 'en'){//if it should be english then load the english header("Location: $pagenamearray[0].php"); exit; } if($_SESSION['language'] == 'pl'){ //construct the name of the file if it existed filename.pl.php $plVersion = $pagenamearray[0] . ".pl.php"; //we have to check if a pl version actually exists of this page if(file_exists($plVersion)){//redirect if it exists header("Location: $plVersion"); exit;//stop executing things }else{$pagelangnotfound = true;} } } ?> header.php <?php if ($_SESSION['language'] != 'en'){ echo 'Select Language: <a href="'. $_SERVER['PHP_SELF'] . '?lang=en"><img src="img/gb.gif" alt="English" class="off" /></a>'; }else{echo 'Wybierz J&#281;zyk: <img src="img/gb.gif" alt="English" />';} ?> <?php if ($_SESSION['language'] != 'pl'){ echo '<a href="'. $_SERVER['PHP_SELF'] . '?lang=pl"><img src="img/pl.gif" alt="Polish" class="off" /></a>'; }else{ echo '<img src="img/pl.gif" alt="Polish" />'; } ?> menu.php <?php if($pageOn == 'index.php'){?> id="selected"<?php }?>> <a href="index.php">Main Page</a> page.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> English content page.pl.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> Polish content
×
×
  • 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.