Languages url path

Discussion in 'MySQL' started by coladeu, May 17, 2012.

  1. #1
    I need to acces my languages in my site from direct url like mysite.com/index.php?language=en and i don't know how to do it or if is possible on the script that i have..
    here is the code how languages works
    function setlang( $spr )
    {
        @session_start;
        $url = parse_url( WEB_PATH );
        if ( substr( $url['host'], 0, 3 ) == "www" )
        {
            $domain = substr_replace( $url['host'], null, 0, 3 );
        }
        else
        {
            $domain = $url['host'];
        }
        @setcookie( "langcookie", @$spr, @time( ) + @COOKIE_EXPIRE, @COOKIE_PATH, @$domain );
        if ( isset( $_POST['lang_ref'] ) && !preg_match( "/http:\\/\\//", $_POST['lang_ref'] ) )
        {
            $referer = $_POST['lang_ref'];
        }
        else if ( preg_match( "~".str_replace( "www", "", WEB_PATH )."~is", str_replace( "www", "", $_SERVER['HTTP_REFERER'] ) ) )
        {
            if ( preg_match( "/\\?lang=(.*)/", $_SERVER['HTTP_REFERER'] ) )
            {
                $referer = preg_replace( "/\\?lang=(.*)/", "", $_SERVER['HTTP_REFERER'] );
            }
            else
            {
                $referer = $_SERVER['HTTP_REFERER'];
            }
            $referer = $referer ? $referer."?lang=".$spr : NULL;
        }
        if ( !empty( 'referer' ) )
        {
            @header( @"Location: {$referer}" );
        }
    }
    
    
    function loadlangs( )
    {
        global $lang;
        global $default_lang;
        $query = @mysql_query( "SELECT * FROM languages" );
        echo "<table align=\"center\">".( "\n" )."<tr>";
        while ( $row = mysql_fetch_assoc( $query ) )
        {
            $short = $row['lang_shortcut'];
            $name = $row['lang_name'];
            $img = $row['lang_image'];
            $img_off = $row['lang_image_off'];
            if ( $short == $_COOKIE['langcookie'] || $short == $default_lang && empty( $_COOKIE['langcookie'] ) )
            {
                echo "<td>\n\t\t\t<img src=\"".WEB_PATH.$img_off."\" alt=\"".$lang['2']." ".$name."\" title=\"".$lang['2']." ".$name."\" />\n\t\t\t</td>".PHP_EOL;
            }
            else
            {
                echo "<td>\n\t\t\t<form method=\"post\">\n\t\t\t<input type=\"image\" src=\"".WEB_PATH.$img."\" alt=\"".$lang['3']." ".$name."\" title=\"".$lang['3']." ".$name."\" name=\"lang\" value=\"".$short."\" style=\"padding:0; margin:0\" />\n\t\t\t<input type=\"hidden\" name=\"lang\" value=\"".$short."\" />\n\t\t\t<input type=\"hidden\" name=\"lang_ref\" value=\"".$_SERVER['REQUEST_URI']."\" />\n\t\t\t</form>\n\t\t\t</td>".PHP_EOL;
            }
        }
        echo "</tr></table>";
    }
    
    Code (markup):
    if someone can look on this and tell me if is there any way to access directly the languages from url will be nice
     
    coladeu, May 17, 2012 IP
  2. dvduval

    dvduval Notable Member

    Messages:
    3,372
    Likes Received:
    356
    Best Answers:
    1
    Trophy Points:
    260
    #2
    I think a more in depth look at the script would be needed to answer the question.
     
    dvduval, May 24, 2012 IP