Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Webmaster Zone > Web Development
Register

Reply
 
LinkBack Thread Tools
Old 10.05.2007, 20:10   #1
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Question session_start(); problem

<?php
session_start();
$lang = $_SESSION["lang"];
if (!$lang) {$lang = $_GET['lang'];}
if ($lang == "ru") {
require("./data/languages/ru.php");
$_SESSION["lang"] = "ru";
}
else{
require("./data/languages/en.php");
$_SESSION["lang"] = "en";
}
?>

joxovurt jan ogneq eli, esor inch vor uxexs anjatvaca chem jogum vonc karelia dzel?
uzum em vor skzbic nayi lang ete ka session-i mech stana "ru"-a te "en", ete chka session-i mech get methodov vekali arjeq@ lang-i u gri session-i mej vor myus ejerum mna et en-@ kam ru-n... hima problems nranuma, vor mi angam inq@ mtav get metodov vekalec asenq ru arjeq@, grec sessioni mej, baic heto vor grum em ?lang=en arden chi poxum, mnuma hin session@ =\ vonc karelia dzel?
__________________
http://megauploader.net/ ------ new designed, new engine powered now still free, fast and without registration...
Reply With Quote
Old 10.05.2007, 20:57   #2
Дошкольник
 
Join Date: 10 2004
Location: Yerevan
Age: 29
Posts: 116
Downloads: 8
Uploads: 0
Reputation: 2 | 0
Default

PHP Code:
<?php 
session_start
(); 
$lang $_SESSION['lang']; 

if(empty(
$lang)) 
{
    switch(
$_GET['lang'])
    {
        case 
"ru":
            
$_SESSION['lang'] = "ru";
            break;

        default:
            
$_SESSION['lang'] = "en";
            break;
    }

?>
Please test it.
Reply With Quote
Old 10.05.2007, 21:03   #3
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

may I ask? Inchna break anum ete cikl chka? O.o
Reply With Quote
Old 10.05.2007, 21:12   #4
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

так я и думал... чашхатец ((( тарс ора есор
Reply With Quote
Old 10.05.2007, 21:30   #5
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

ExtremeSM, qo logikan a sxal.

Hly karda ushadir inch es grel`

Quote:
uzum em vor skzbic nayi lang ete ka session-i mech stana "ru"-a te "en", ete chka session-i mech get methodov vekali arjeq@ lang-i u gri session-i mej vor myus ejerum mna et en-@ kam ru-n...
1. Skzbic nayec lang ka sessioni mej te che
2. Ka (qani vor naxord requestic arden set er exel)
3. Hetevabar $_GET['lang']-y arden chi ditarkvum, qani vor du inqd es uzum vor`

Quote:
ete ka session-i mech stana "ru"-a te "en", ete chka session-i mech get methodov vekali arjeq@ lang-i u gri session-i mej
Reply With Quote
Old 10.05.2007, 21:39   #6
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Quote:
Originally Posted by ExtremeSM View Post
may I ask? Inchna break anum ete cikl chka? O.o

http://am.php.net/manual/en/control-...ures.break.php

Quote:
break ends execution of the current for, foreach, while, do-while or switch structure.

break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.
Reply With Quote
Old 10.05.2007, 21:51   #7
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

Silver jan, vabsheto es el tenc heto mtaceci, uxxaki asum em uxexs anjatvaca hima...
baic stacvec voncvor, tu-tu-tu achkov chtanq

<?php
session_start();
if (!$_GET["lang"]) {$lang = $_SESSION["lang"];}
else {$lang = $_GET["lang"];} //STEX VOR ELSE AVELACRI EXAV =)))))))

if ($lang == "ru") {
require("./data/languages/ru.php");
$_SESSION["lang"] = "ru";
}
else{
require("./data/languages/en.php");
$_SESSION["lang"] = "en";
}
?>
Reply With Quote
Old 10.05.2007, 22:05   #8
наивная дурочка
 
TasteMyLipstick's Avatar
 
Join Date: 10 2005
Location: бродяжка я
Age: 33
Posts: 196
Downloads: 0
Uploads: 0
Reputation: 25 | 3
Default

PHP Code:
<?php
session_start
();
$a_languages = array('en''ru');
$lang '';

if (isset(
$_GET['lang']) && in_array($_GET['lang'], $a_languages)) {
    
$_SESSION["lang"] = $_GET['lang'];
}
else if (isset(
$_SESSION["lang"]) && in_array($_SESSION["lang"], $a_languages)) {
}
else {
    
$s_lang "";
    foreach(
$a_languages as $language) {
        
$s_lang .= " <a href=\"?lang=$language\">$language</a>\r\n";
    }
    exit(
"Choose your language$s_lang");
};

$lang $_SESSION["lang"];
require(
"./data/languages/$lang.php");
?>

Last edited by TasteMyLipstick; 14.05.2007 at 01:02.
Reply With Quote
Old 10.05.2007, 22:07   #9
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Here's an (IMHO) better way of writing the same thing:

PHP Code:
<?php
    session_start
();

    
$lang = (isset($_GET['lang']) ? $_SESSION['lang'] : $_GET['lang'];


    if (
language_exists($lang))
    {
        require(
'./data/languages/' $lang '.php');
        
$_SESSION['lang'] = $lang;
    }
?>
And there still are security issues I guess.
Reply With Quote
Old 12.05.2007, 05:25   #10
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

TasteMyLipstick -i dzev@ shat bard er, наверное это не для меня О.о

Silver jan, prosto vor ashxatuma, el haves chka dzer talu, baic qo asac dzev@ aveli sirun dzev er.

P.S.
$lang = (isset($_GET['lang']) ? $_SESSION['lang'] : $_GET['lang'];

es tox@ chisht em haskacel?
?-@ nshanakuma, vor stugi ete lang-@ get metodov arden tvaca, uremn pahi session-um, ete che, vekali henc get-ic ha? =)
Reply With Quote
Old 12.05.2007, 07:22   #11
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

En im dzevov arden exav qceci serveri vra arden, baic mi harc unem, vonc en poxum "input type=file"-i "browse" grac@??? vabshe hnaravora?
Reply With Quote
Old 12.05.2007, 07:43   #12
полюбому йес эм...
 
Mesrop's Avatar
 
Join Date: 02 2005
Location: near the computer
Age: 26
Posts: 3,243
Downloads: 3
Uploads: 0
Reputation: 129 | 3
Default

Quote:
Originally Posted by ExtremeSM View Post
En im dzevov arden exav qceci serveri vra arden, baic mi harc unem, vonc en poxum "input type=file"-i "browse" grac@??? vabshe hnaravora?
inchqan jogelem dzev chi... baysde hnaravora vor javascriptov, css-ov miban stasvi
Reply With Quote
Old 12.05.2007, 08:31   #13
Дошкольник
 
Join Date: 10 2004
Location: Yerevan
Age: 29
Posts: 116
Downloads: 8
Uploads: 0
Reputation: 2 | 0
Default

If it's not required to use $lang:

PHP Code:
if(isset($_GET['lang']))
{
    if(
language_exists($_GET['lang']))
    {
        
$_SESSION['lang'] = $_GET['lang'];
    }
}

require(
'./data/languages/' $_SESSION['lang'] . '.php'); 
Anyway, you must keep session scope clean to have it reliable, so it should be safe to include $_SESSION['lang'].php;
Also you may provide more detailed error reporting, this way.
Reply With Quote
Old 12.05.2007, 12:41   #14
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

tnx lol
tencel kporcem teche eli inch vor sksec tvarutyunner anel kods =\
Reply With Quote
Old 12.05.2007, 17:02   #15
I Love BMW!
 
ExtremeSM's Avatar
 
Join Date: 11 2006
Location: reload();
Posts: 63
Downloads: 2
Uploads: 0
Reputation: 0 | 0
Default

joxovurt lav mi kerp "на соплях" ashxatuma, baic mi ban mnac, vonc et browse-@ anem? luboj dzevov, css-ov JS-ov, vor gri Обзор kam mi ban urish?
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 21:41.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.