Jump to content

cookie problem


Amy1980

Recommended Posts

Hello Boys [and maybe Girls]!

I have problem. I wanna to make my site multi language. I want to make it similar like PHP-Nuke is. I don't want to make it with URLs like
[code]index.php?lang=de[/code]

W would like to make it on cookies. Can You help me? I was trying for few days but I didn't make nothing right. Can You help me?

Thanx in advance!!

edit:

I found something interesting
[url=http://www.phpfreaks.com/forums/index.php/topic,112507.0.html]http://www.phpfreaks.com/forums/index.php/topic,112507.0.html[/url]

but this user has wrote new topic that cookies doesn't work. Do You think is it good way? If yes, what to do with cookies?
Link to comment
Share on other sites

You could use a language directory, and in the directory you have some php files..

And each file (Named its language ie: english.php) will have aload of DEFINES..
So you can have say

DEFINE("WORDONE", "DIFFLANG")
DEFINE("WORDTWO", "WORDTWOIN A DIFF LANG")

That way in your main files you have just to echo WORDONE, and it will display its value, now to set up to choose the language you would have say...
(BTW: To change the lang use GET in urls... mydomain.com/index.php?lang=french)

$language = $_GET['lang'];
$langfile = "/languages/" . $language . ".php"
if (file_exists(/languages/$language.php){
require("$langfile");
} else //if GET lang not set just use ENGLISH as default...
require("/languages/english.php");
}

And then you just have to put all words that are defined as CAPS.. and they will come up in the languages....

If you dont understand that please post and i will try go more into debth..
If its the code you dont understand, have a look around for what some of that code would do.. but if you understand the code, and not the concept let me know and i can explain more...


Abydos

PS: I copyed this post from when i posted it in the topic at http://www.phpfreaks.com/forums/index.php/topic,115196.0.html
Link to comment
Share on other sites

There are many ways.. On the main page of your website have a dropdown box with languages.. and when the user selects one, and sends the form, process it and save the language they want in a session or cookie.. then just call the session or cookie to a variable and include that language file!

Understand? if not i can explain more :D
Link to comment
Share on other sites

I decided to make it with pedro84's method. It seems good to me.

Ok. I wanna to make cookie to this method but I couldn't:/

This is it

index.php
[code]<?php
session_start();
require_once("langman.php");
if(!SelectLanguage ($_SESSION["lang"]))
die ("Error");
?>
[/code]

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;
}
?>[/code]

setlang.php
[code]<?php
session_start();
$strLang = $_GET["lang"];
$_SESSION["lang"] = stripslashes($strLang);
header("Location: index.php"); //** redirect to where u want...
?>[/code]


Setlang.php changes laguages but I have big problem with adding cookie to this file. Can Anyone help my?:> Hmm I think i must add cookie to setlang.php;)
Link to comment
Share on other sites

I could show you how to do it with sessions, cause i dont use cookies :P

[code]
<?php
if (!$_SESSION['language']){
$language = "english.php";
} else {
$language = $_SESSION['language'];
}
require("/languages/$language");
?>
[/code]

Just make sure when you set the session (or cookie whatever way you do it) to include the .php; :P
Link to comment
Share on other sites

[quote author=taith link=topic=116754.msg476191#msg476191 date=1164893772]
[code]
<?
(isset($_COOKIE[Lang])) ? require_once('lang/'.$_COOKIE[Lang].'.php') : require_once('lang/english.php');
?>
[/code]

then all ya gotta do is set that cookie "Lang" to any language it wants, and it will load that language file :-)
[/quote]

Where to put it?:> :D
Link to comment
Share on other sites

Hmm.
It could be, but I'm looking for something with sessions and cookies. I;m thinking all the free time of the isset, but I cannot write it correctly.
I used something like that:
[code]
include ('news_ '.$_SESSION['lang'].'/index.php
[/code]

When users choose Polish lang, it includes news_pl/index.php.

I wanna to make something like this:
[code]
include (news_ if exist $_COOKIE['lang'] /if don't $_SESSION['lang']/index.php
[/code]

You know what I mean?
It must be simple. PHP-Nuke by F. Burzi works this way.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.