SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Isset problem / multi language site

    Hello People!
    I have following problem:
    I make multi language site this way:

    index.php
    Code:
    <?php
    session_start();
    require_once("langman.php");
    if(!SelectLanguage ($_SESSION["lang"]))
    	die ("Error");
    ?>
    langman.php
    Code:
    <?php
    $language = array();
    function SelectLanguage($strLang)
    {
    	global $language;
    	
    	$inc = "en";
    	switch(stripslashes($strLang))
    	{
    		case "de":
    			$inc = "de";
    		break;
    		
    		case "en":
    			$inc = "en";
    		break;
    
    		case "pl":
    			$inc = "pl";
    		break;
    		
    		default:
    			$inc = "en";
    	}
    	
    
    	include_once("languages/" . $inc . ".inc");
    	if(isset($lang))
    	{
    		$language =  $lang;
    		return true;
    	}
    
    	return false;
    }
    ?>
    setlang.php
    Code:
    <?php
    session_start();
    $strLang = $_GET["lang"];
    $_SESSION["lang"] = stripslashes($strLang);
    header("Location: index.php"); //** redirect to index.php
    ?>
    Language are changing by setlang.php which calls index.php. Everything is ok.
    As You see I don't use URL's. I'm calling each languages for this way:
    Code:
    <?php echo $language["love"] ?>
    I have big problem. It all works on sessions, but I'd like to send cookies to. But I don't know how to do
    I was trying all night long, and I didn't make it working.

    Should I send cookie in setlang.php or index.php?
    Where put isset? If cookie exist, use cookie's language, if not send cookie and use choosen lang.

    As you surely see, I'm php newbie and I need Your help.

    Does anyone know what have I to do?


    Edit

    When I put
    Code:
    <?php
    session_start();
    $strLang = $_GET["lang"];
    setcookie('lang', $_GET['lang']);
    $_SESSION["lang"] = stripslashes($strLang);
    header("Location: index.php"); //** redirect to where u want...
    ?>
    in setlang.php and checking with
    Code:
    <?php echo $_COOKIE['lang']; ?>
    I get "de" [German language] but when session edns, I close browser and visit again site I have default language.
    Last edited by pedro1984; Nov 30, 2006 at 04:47. Reason: Changing point of the question

  2. #2
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put
    Code:
    $Month = 2592000 + time();
    //this adds 30 days to the current time
    setcookie(lang, $_GET['lang'], $Month);
    if(isset($_COOKIE['lang']))
    {
    $strLang = $_COOKIE['lang'];
    }
    else
    {
    setcookie(lang, $_GET['lang'], $Month);
    }
    in my setlang.php and cookie is written but how to force script to read language from cookie?:>

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pedro, welcome to the forums

    try this
    PHP Code:
    # index.php

    if(isset($_COOKIE['lang'])) 
       
    $param $_COOKIE['lang'];
    else
       
    $param 'en'// your "default" language
    SelectLanguage($param);

    # setlang.php

    if(isset($_GET['lang'])) 
       
    $param $_GET['lang'];
    else
       
    $param 'en'// your "default" language

    setcookie('lang'$param$time);
    header("Location: .... etc 

  4. #4
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have to change any lines with Your suggestions or put it intead?

  5. #5
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm... i tried and doesn't work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •