Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-11-2005, 01:17 AM   PM User | #1
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
Post after set style is done.... looking to set LANG

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

PHP Code:
<?   
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 Code:
<?php

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


?>
and in arabic.php

PHP Code:
<?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



Last edited by muhaidib; 06-11-2005 at 03:25 AM..
muhaidib is offline   Reply With Quote
Old 06-11-2005, 02:23 AM   PM User | #2
xiaodao
Regular Coder

 
Join Date: Sep 2004
Posts: 713
Thanks: 6
Thanked 2 Times in 2 Posts
xiaodao is an unknown quantity at this point
i went to your site, nothing wrong the style chooser
__________________
flying dagger
xiaodao is offline   Reply With Quote
Old 06-11-2005, 02:51 AM   PM User | #3
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
Well this:
PHP Code:
include ("lang/'.$lang_sheet.'.php"); 
Should probably be written as:
PHP Code:
include ("lang/$lang_sheet.php"); 
Or as:
PHP Code:
include ('lang/'.$lang_sheet.'.php'); 
As for the headers already sent error, this is most likely being cause by this bit of code:
PHP 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.
__________________
~ Bazzy

Last edited by delinear; 06-11-2005 at 02:54 AM..
delinear is offline   Reply With Quote
Old 06-11-2005, 02:51 AM   PM User | #4
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
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 is offline   Reply With Quote
Old 06-11-2005, 03:03 AM   PM User | #5
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
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 is offline   Reply With Quote
Old 06-11-2005, 03:05 AM   PM User | #6
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
here is the code up to </head> in index.php

PHP Code:
<?   
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 is offline   Reply With Quote
Old 06-11-2005, 03:11 AM   PM User | #7
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
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
PHP Code:
WarningCannot modify header information headers already sent by (output started at c:webindex.php:13in c:webindex.php on line 21 
muhaidib is offline   Reply With Quote
Old 06-11-2005, 03:19 AM   PM User | #8
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
As I said before, I think this is being caused by the following (see my comments in the code for further explanation):

PHP Code:
<?    
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:
PHP Code:
<?    
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']))
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-11-2005, 03:19 AM   PM User | #9
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
okay... i got all the errors to go away,, but the lang does not change...

updated...

this is index.php

PHP Code:
<?   
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

Code:
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..
muhaidib is offline   Reply With Quote
Old 06-11-2005, 03:23 AM   PM User | #10
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
You are still setting the wrong cookie name for the language:
PHP Code:
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:
PHP Code:
setcookie('lan',$style_sheet,time()+999999999); 
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-11-2005, 04:02 AM   PM User | #11
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
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..
muhaidib is offline   Reply With Quote
Old 06-11-2005, 07:22 AM   PM User | #12
dumpfi
Regular Coder

 
Join Date: Jun 2004
Posts: 565
Thanks: 0
Thanked 18 Times in 18 Posts
dumpfi will become famous soon enough
I think the second should be set like this:
PHP Code:
setcookie('lan',$lang_sheet,time()+999999999); 
dumpfi
dumpfi is offline   Reply With Quote
Old 06-11-2005, 05:12 PM   PM User | #13
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
okok,,, hummm

i uploaded it into a test file,,,

right here

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


the index is like this

PHP Code:
<?    
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 Code:
<?php

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

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

lang/arabic.php

PHP Code:
<?php

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

?>
muhaidib is offline   Reply With Quote
Old 06-11-2005, 06:27 PM   PM User | #14
Kurashu
Regular Coder

 
Join Date: Aug 2004
Location: The US of A
Posts: 767
Thanks: 1
Thanked 0 Times in 0 Posts
Kurashu is an unknown quantity at this point
PHP Code:
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.
Kurashu is offline   Reply With Quote
Old 06-12-2005, 03:17 AM   PM User | #15
muhaidib
Regular Coder

 
Join Date: May 2005
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
muhaidib is an unknown quantity at this point
thanx

but i got the error

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

this is the index.php

PHP Code:
<?    
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 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:01 AM.


Advertisement
Log in to turn off these ads.