Jump to content

[SOLVED] Sessions


SkyRanger

Recommended Posts

finally almost got my multi languages working on my script except for one major detail.

 

Here is situation

 

I want a visitor to choose a flag for his language ie:

 

en_flag.gif

fr_flag.gif

sp_flag.gif

etc_flag.gif

 

Can anybody give me an example of how to make a session for this or point me to a tutorial to read on how to make a session for this, I have been searching for this for the past 3 days with no luck so far.

 

Here is the code I am using:

 

if (empty($_SESSION['language']['lid'])) {
$_SESSION['language']['lid'] = $newlang;
}

in a file called get_language.php

 

and this in my main.php

 

include "./inc/get_language.php";

include "./lang/".$path."/install.lang.php";

 

Please any assistance would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/46615-solved-sessions/
Share on other sites

make the images links that will send the language ID to the address bar and use the $_GET method to retrieve the data and insert it into your session. don't forget to check it it !isset(), not just empty().

 

Thanks boo, yeah, I have figured out how to make the images links send the language  id to the address bar, the only problem I can't figure out is sessions.  I honestly do not know how to post to the session.  That is why I need help.  $me bows head for being so annoying..lol.  But could somebody please either a] help me with an example or b] direct me to a sessions for dummies tutorial...lol

Link to comment
https://forums.phpfreaks.com/topic/46615-solved-sessions/#findComment-226966
Share on other sites

the code you had is pretty close.

 

to set the $_SESSION data:

<?php
        if(!isset($_SESSION['language']) || empty($_SESSION['language'])){
                $_SESSION['language'] = 'English';
        }elseif(isset($_GET['langID'])){
                $_SESSION['language'] = $_GET['langID'];
        }
?>

 

to allow the user to change the language by clicking a flag:

<?php
        $languages = array('English' => 'flag1.jpg', 'Spanish' => 'flag2.jpg', 'French' => 'flag3.jpg');

        foreach($languages as $lang => $flag){
                echo "<a href=\"". $_SERVER['php_self'] ."?langID=". $lang ."\">";
                echo "<img src=\"". $flag ."\">";
                echo "</a>\n";
        }
?>

Link to comment
https://forums.phpfreaks.com/topic/46615-solved-sessions/#findComment-226975
Share on other sites

You guys are so AWSOME.  It works exactly like I needed it to.

 

I would like to create a tutorial on how others can use this script, with what I have and what you guys have given me, and was wondering if it is ok if I use your usernames in the tutorial to give you credit for what you have offered me?

Link to comment
https://forums.phpfreaks.com/topic/46615-solved-sessions/#findComment-227002
Share on other sites

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.