...

View Full Version : after set style is done.... looking to set LANG



muhaidib
06-11-2005, 01:17 AM
hey all,,, i installed apache/php/mysql in my PC..

and i want to install another dropdown box aside from the style choser in my site www.7des.com

sO..

this is what i done..


index.php


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';
}

setcookie('css',$style_sheet,time()+999999999);

?>

<?
if (isset($_POST['lang']))
{
$lang_sheet = $_POST['lang'];
} else {
$lang_sheet = !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'en';
}

setcookie('css',$style_sheet,time()+999999999);

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<?php
echo '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">';
?>
<?php
include ("lang/'.$lang_sheet.'.php");
?>

<title>lang test</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="800" class="none" id="table1">
<tr>
<td width="11%"><font size="1" color="#666666">
<form name="style" method="post">
<br>
<select name="style" class="field" size="1" onChange="document.style.submit();">
<option selected>-----</option>
<option value="default">Fire Grey</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
&nbsp;style</form>
<form>
<br>
<select name="lang" class="field" size="1" onChange="document.lang.submit();">
<option selected>-----</option>
<option value="english">en</option>
<option value="arabic">ar</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
lang</form>
</font></td>
</tr>
</table>
<p>the code &lt;?php echo $lang['lang'] ?&gt; is in the next line,, if its set to
english then it should echo&nbsp; &quot;lang is english&quot; and in arabic it should echo
&quot;lang is arabic&quot;</p>
start of code -------( <?php echo $lang['lang'] ?> )------- end of code
</body>

</html>


and lang/english.php


<?php

$lang['lang'] = 'lang is english';


?>

and in arabic.php


<?php

$lang['lang'] = 'lang is arabic';

?>


by the way i kept the style selector just to conform that it still works,,,

so when i opend index.php i fot the following


http://www.7des.com/upload/upload/lang.JPG

xiaodao
06-11-2005, 02:23 AM
i went to your site, nothing wrong the style chooser

delinear
06-11-2005, 02:51 AM
Well this:

include ("lang/'.$lang_sheet.'.php");
Should probably be written as:

include ("lang/$lang_sheet.php");
Or as:

include ('lang/'.$lang_sheet.'.php');

As for the headers already sent error, this is most likely being cause by this bit of code:

?>

<?
if (isset($_POST['lang']))
{
$lang_sheet = $_POST['lang'];
} else {
$lang_sheet = !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'en';
}

setcookie('css',$style_sheet,time()+999999999);

?>
You close the PHP tags, insert a newline and then open the PHP tags again. Unfortunately that newline gets sent to the browser which means no more headers can be sent so as soon as you try and write the following cookie (which has to be sent with the header data) it generates the header already sent error. If you are sending headers from PHP, including writing sessions or cookies, then it cannot be stressed enough that you can't output anything to the browser at all before you do so, not even a single little whitespace. Just get rid of the ?> <? at the start of that section of code and hopefully the error should go away.

Incidentally, in this code snippet you are setting a cookie called css but then trying to access a cookie called lan, I assume you meant to have setcookie('lan',$style_sheet... etc.

muhaidib
06-11-2005, 02:51 AM
lol i know,,,

i was talking about adding a LANG selector aside to the style choser

i didn't even upload the lang info

the tests above where done on my PC (i have apache/php installed)

muhaidib
06-11-2005, 03:03 AM
ohhh delinear we posted in the same minutes what are the odds lol,,,

thanx for your info :)

i fixed the spelling mistake,, but the script is still broken

but thank you any ways :)

muhaidib
06-11-2005, 03:05 AM
here is the code up to </head> in index.php


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';
}

setcookie('css',$style_sheet,time()+999999999);

?>

<?
if (isset($_POST['lang']))
{
$lang_sheet = $_POST['lang'];
} else {
$lang_sheet = !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'en';
}

setcookie('css',$style_sheet,time()+999999999);

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<?php
echo '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">';
include ('lang/'.$lang_sheet.'.php');
?>

<title>lang test</title>
</head>

muhaidib
06-11-2005, 03:11 AM
ohh ohh wait a sec!

there was a wrong file mistake,,, there was "en" and "english"..

so i fixed that,, the only problem left is
Warning: Cannot modify header information - headers already sent by (output started at c:\web\index.php:13) in c:\web\index.php on line 21

delinear
06-11-2005, 03:19 AM
As I said before, I think this is being caused by the following (see my comments in the code for further explanation):


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';
}

setcookie('css',$style_sheet,time()+999999999);

// you're closing the php tags here and inserting a newline, this causes the headers to be sent before your second cookie can be set!
?>

<?
// and now you're opening the php tags again but the damage has been done, delete these two tags and you should be fine
if (isset($_POST['lang']))

If you delete the two tags where I put the comment above it should fix the problem:

<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';
}

setcookie('css',$style_sheet,time()+999999999);

if (isset($_POST['lang']))

muhaidib
06-11-2005, 03:19 AM
okay... i got all the errors to go away,, but the lang does not change...

updated...

this is index.php


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['css']) ? $_COOKIE['css'] : 'default';
}

setcookie('css',$style_sheet,time()+999999999);


if (isset($_POST['lang']))
{
$lang_sheet = $_POST['lang'];
} else {
$lang_sheet = !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'english';
}

setcookie('css',$style_sheet,time()+999999999);

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<?php
echo '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">';
include ('lang/'.$lang_sheet.'.php');
?>

<title>lang test</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="800" class="none" id="table1">
<tr>
<td width="11%"><font size="1" color="#666666">
<form name="style" method="post">
<br>
<select name="style" class="field" size="1" onChange="document.style.submit();">
<option selected>-----</option>
<option value="default">Fire Grey</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
&nbsp;style</form>
<form>
<br>
<select name="lang" class="field" size="1" onChange="document.lang.submit();">
<option selected>-----</option>
<option value="english">en</option>
<option value="arabic">ar</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
lang</form>
</font></td>
</tr>
</table>
<p>the code &lt;?php echo $lang['lang'] ?&gt; is in the next line,, if its set to
english then it should echo&nbsp; &quot;lang is english&quot; and in arabic it should echo
&quot;lang is arabic&quot;</p>
start of code -------( <?php echo $lang['lang'] ?> )------- end of code
</body>

</html>


and the lang files are still the same,,



i mean when i enter it says


the code <?php echo $lang['lang'] ?> is in the next line,, if its set to english then it should echo "lang is english" and in arabic it should echo "lang is arabic"

start of code -------( lang is english )------- end of code

but when i change the lang drop down nothing happens..

delinear
06-11-2005, 03:23 AM
You are still setting the wrong cookie name for the language:

if (isset($_POST['lang']))
{
$lang_sheet = $_POST['lang'];
} else {
$lang_sheet = !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'english';
}

setcookie('css',$style_sheet,time()+999999999);
What happens here is that the language gets stored in the "css" cookie. Then the css file gets written over the top of it (since cookies get written in reverse order for some reason).

You meant to put the following, I'm sure:

setcookie('lan',$style_sheet,time()+999999999);

muhaidib
06-11-2005, 04:02 AM
ohhh ok :)

thanx

i edited it,,

but still,, there is something in the SECOND form that is wrong... it does not change the lang,, maybe its something in the FORM that is not responding..

dumpfi
06-11-2005, 07:22 AM
I think the second should be set like this:

setcookie('lan',$lang_sheet,time()+999999999); dumpfi

muhaidib
06-11-2005, 05:12 PM
okok,,, hummm

i uploaded it into a test file,,,

right here

http://www.7des.com/php/index.php


the index is like this


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['style']) ? $_COOKIE['style'] : 'default';
}

setcookie('style',$style_sheet,time()+999999999);


if (isset($_POST['lang']))
{
$lang= $_POST['lang'];
} else {
$lang= !empty ($_COOKIE['lan']) ? $_COOKIE['lan'] : 'default';
}

setcookie('lan',$style_sheet,time()+999999999);

?>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<?php
echo '<link rel="stylesheet" type="text/css" href="styles/'.$style_sheet.'.css">';
?>
<?php
include ("lang/$lang.php");
?>

<title>lang test</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="800" class="none" id="table1">
<tr>
<td width="11%"><font size="1" color="#666666">
<form name="style" method="post">
<br>
<select name="style" class="field" size="1" onChange="document.style.submit();">
<option selected>-----</option>
<option value="default">Fire Grey</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
</form>
<form>
<select name="lan" class="field" size="1" onChange="document.lan.submit();">
<option selected>-----</option>
<option value="default">en</option>
<option value="arabic">ar</option>
</select>
<noscript>
<input type="submit" class="field" />
</noscript>
</form>
</font></td>
</tr>
</table>
<p>the code &lt;?php echo $lang['lang'] ?&gt; is in the next line,, if its set to
english then it should echo&nbsp; &quot;lang is english&quot; and in arabic it should echo
&quot;lang is arabic&quot;</p>
start of code -------( <?php echo $lang['lang'] ?> )------- end of code
</body>

</html>


and the lang/default.php is this


<?php

$lang['lang'] = 'english';

?> and if you noticed in the site it just says the first letter,,

lang/arabic.php


<?php

$lang['lang'] = 'arabic';

?>

Kurashu
06-11-2005, 06:27 PM
function getLang()
{
if(isset($_COOKIE['lan']))
$lang = $_COOKIE['lan'];
switch($lang)
{
case 'en':
case 'english':
default:
require_once 'lang/english.php';
break;

case 'ar':
case 'arabic':
require_once 'lang/arabic.php';
break;
}
}
else
{
require_once 'lang/english.php';
}

return true;
}


Try using this.

muhaidib
06-12-2005, 03:17 AM
thanx :)

but i got the error


Parse error: parse error, unexpected T_ELSE in /home/adescom/public_html/php/index.php on line 30


this is the index.php


<?
if (isset($_POST['style']))
{
$style_sheet = $_POST['style'];
} else {
$style_sheet = !empty ($_COOKIE['style']) ? $_COOKIE['style'] : 'default';
}

setcookie('style',$style_sheet,time()+999999999);


function getLang()
{
if(isset($_COOKIE['lan']))
$lang = $_COOKIE['lan'];
switch($lang)
{
case 'en':
case 'english':
default:
require_once 'lang/english.php';
break;

case 'ar':
case 'arabic':
require_once 'lang/arabic.php';
break;
}
}
else //LINE 30
{
require_once 'lang/english.php';
}

return true;
}


setcookie('lan',$style_sheet,time()+999999999);

?>

muhaidib
06-12-2005, 03:23 AM
you know what :)


every body its ok,, forget about it!

i will just keep it english lol,,

thanx for all your help i really appreciate it :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum