Help - Search - Members - Calendar
Full Version: PHP and sending more than 1 parameter
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
HEki_
Hi,

i have found a great tutorial on how to use php to simple create a navigation and than links here:
http://www.sebastiansulinski.co.uk/tutoria...nd_page_include
(if its not allowed to post links please remove it)

lets say i will have my web page in 2 languages. and i will have 3 subpages (home, links, contacts)
Ill put a little flags icons in top right corner for selecting a language.

So now lets say i open up the links page and i click on a different language. How do i store the previous
page i was on and show up the same page in a different language?

Hope i made it clear enough for you guys to understand what i am trying to achieve.

Best regards,
HEki
rc69
$_SERVER['HTTP_REFERER'] (ref: http://php.net/manual/en/reserved.variables.server.php)

That will basically tell you what page the current request was called from. So you can essentially just redirect back to it. You should use caution though, as i here certain Anti-viruses actually block this variable from being sent to the server.

Another option would be to just tack $_SERVER['REQUEST_URI'] onto the "change language" link's query string, and redirect back to that.

And yet another option, which i would recommend: Just add the language you want to use as part of the query string of the current page, and then process from there. i.e:
CODE
if($_GET['lang'] == 'en-us'){
    // Change the language
}

// Continue loading the site in the new language without having to redirect
NDBoost
Here is an example of using a session var for storing the localization (langauge) type. All you then would need to figure out is how you want to interpret the URL and pass that on to the links. If it were me, i would throw the query_string into an array. then call the ?n array in the language change URLs.

The benefit for using a session/cookie is users wont have to keep changing the language on every page visit, (IE Home, Links Contacts etc).. Its stored in a session and for every page visit it will check the session['localization'] and display the correct language..

CODE
<?php
session_start();
$localization = $_SESSION['localization']; //Language session vars
?>
    <table width="400" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><div id="right"> <a href="">en-us</a><br/>
          <a href="?l=en-gb">en-gb</a><br/>
        </div></td>
      </tr>
      <tr>
        <td colspan="2">
<?php
switch ($_GET['l']){
    default:
        if (isset($localization) && $localization =='en-us') {
        echo 'This is the en-us language';
        }else {
            $localization = 'en-us';
            echo '$localization set to en-us';
            echo 'This is the en-us language';
        };
    break;
    case 'en-gb':
        if (isset($localization) && $localization =='en-gb') {
        echo 'This is the en-gb language';
        }else {
            $localization = 'en-gb';
            echo '$localization set to en-gb';
            echo 'This is the en-gb language';
        }
    break;
}
?></td>
      </tr>
    </table>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.