davvid Posted March 16, 2012 Share Posted March 16, 2012 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ę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 Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/ Share on other sites More sharing options...
davvid Posted March 25, 2012 Author Share Posted March 25, 2012 bump Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/#findComment-1330893 Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 Did you want page.php?lang=pl to resolve to page.pl.php? or are you saying that when this link is generated - it points to page.pl.php? Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/#findComment-1330896 Share on other sites More sharing options...
davvid Posted March 25, 2012 Author Share Posted March 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/#findComment-1330976 Share on other sites More sharing options...
bspace Posted March 25, 2012 Share Posted March 25, 2012 as far as i can see it's doing what it's supposed to pointing to page.pl.php you still have'nt said what you actually want it to do that's different to this why would you want it to be different? looks workable to me Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/#findComment-1330979 Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 I think we need more clarification but if you want to keep the original url then you'd probably at to require or include the relevant file rather than redirect to it. Quote Link to comment https://forums.phpfreaks.com/topic/259090-variable-doesnt-show-up-in-url/#findComment-1331040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.