Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    i went to your site, nothing wrong the style chooser
    flying dagger

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by delinear; 06-11-2005 at 02:54 AM.

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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']))

  • #9
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..

  • #10
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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); 

  • #11
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..

  • #12
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    I think the second should be set like this:
    PHP Code:
    setcookie('lan',$lang_sheet,time()+999999999); 
    dumpfi

  • #13
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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';

    ?>

  • #14
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #15
    Regular Coder
    Join Date
    May 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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);   

    ?>


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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