1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Call XF with the right language from an extern page

Discussion in 'XenForo Development Discussions' started by Robert9, Sep 15, 2016.

  1. Robert9

    Robert9 Active Member

    I use xenforo only as a part of a bigger website. I have my website in two languages. You can switch from every page to the same page in another language.

    from /index.php to /eng/index,php and back


    /impressum.php to /eng/imprint.php

    My xenforo is done int wo languages also. Users can change the language in two ways. The normal way bottom left with "Choose language" and at top left with the link:


    for englisch



    for german.

    My problem is now to call the forums from all external pages. Because i dont want to include xf there, i have no xToken, but without xToken i cant call the forum in the right language.

    I am shure that the programers of xenforo has thought about this problem, but i dont know how to call the forums with the right language from an external page. And i am shure that many people have this problem while having more than one language at their pages.


    with links

    Board in englisch => /forums/index.php?misc/language&language_id=1

    Board in german => /forums/index.php?misc/language&language_id=2

    dont do what it should do!

    I really hope there is a solution, because it is absolutely not userfriendly to have a page in different languages, but show the forum maybe in the worng language.

  2. Mike

    Mike XenForo Developer Staff Member

    The reason for the token is to prevent the language from being changed unexpectedly (such as through an image tag). You can still link to the language changer but it should require user confirmation. When you link like that, for a registered user, you're changing their language preference permanently (as in, the value in their user record) so ensuring that it's triggered by the user is very much intentional.

    I believe the tokenless version will work for guests though.
  3. Robert9

    Robert9 Active Member

    Now i know more.

    What i have now:

    Link for german / english in my header with:


    On extern pages: guests get the right language;

    loggedin user get an error that will confuse them (reload page!)

    at the forum pages i have the same link but with xToken also; here everything is fine.

    What i can do now?

    I dont use the language_id:
    > Logged users have no problem
    > guests have to choose the language

    I use language_id, but i link from extern to a preview page (with XF included, so with xToken and two links: Choose german / english)

    None of both are perfect.
  4. Mike

    Mike XenForo Developer Staff Member

    You're probably going to need a custom page that doesn't do the CSRF token check (or does some other check to validate the request is valid that you can generate from outside XF).
  5. Robert9

    Robert9 Active Member

    Yes, i can link to /languagechooser.php; include XF to have an xToken and offer two links to enter the forum in the right language. But imagine to choose every day your language again, when you come to the site? I dont like the idea.

    If there is no other solution i am sorry for all not german-speaking people, because they have to find the language chooser while they have seen the whole page before in the right language. :(
  6. Robert9

    Robert9 Active Member

    A better solution could be to call XF from extern pages with


    and ask somewhere in XF

    xToken = "HUHU",
    redirect to /forum/index.php

    Is there any reason not to do it in this way?
  7. Mike

    Mike XenForo Developer Staff Member

    Honestly, I'm now confused. My understanding is roughly that this is what you were trying to do initially -- you were wanting links that change/force the user's language (permanently, unless they take steps to change it back). There isn't a link like that you can generate externally as the CSRF token is important for security, so you'd have to stop that in some way with a custom script (or use that custom script to take a different approach).

    I think we need to step back. Your initial post started with looking for a solution, but it didn't make the original problem totally clear. Is the problem that you want users to view the forum in the language they used on the site? Assuming it's all on one domain, you can probably just set a <cookie_prefix>language_id cookie based on the language from your site. That should get picked up when they go to the forum.
  8. Robert9

    Robert9 Active Member


    /index.php (german website)

    /eng/index.php (english website)

    /forum/ Forum with german and english language and a header for the forum as a language-phrase.

    At the top of all pages you find

    left: german / english
    right: forum (or forums at the english page)

    Extern pages:

    Case 1:
    If i have only a link to /forum/ at the extern pages

    Case 1.1: User not loggedin

    I am at /index.php (german page) and jump to /forum/ (with german language as standard)
    I am at /eng/index.php (english page) and jump to /forum/ (with german language as standard) (First english page, suddenly german page!)

    Case 1.2 User is logged in (has choosen his language)

    I am at /index.php (german page) and jump to /forum/ (with user selected language )
    I am at /eng/index.php (english page) and jump to /forum/ (with user selected language)

    >> Correct

    XF Pages:

    Case 1: User not logged in

    /forum/index.php?misc/language&language_id=1&_xfToken=&redirect=/forum/index.php?language_id=1 or

    >> Both links change the language with one click

    Case 1.1: User logged in

    The link english / german at the xf pages (top) is linked to:


    >> Both links change the language with one click

    Conclusion: One problem in red font


    If i use instead of /forum/ the link /forum/index.php?misc/language&language_id=x&_xfToken=&redirect=/forum/index.php

    at the extern pages i get an error if a user is still logged in and jumps to the forum without an xToken.

    I will survive with the first way; and all english people have to find the button to change the language to english to register.
    This feels not profesionell, because after reading some pages in english i await that the forum will come also in english.

Share This Page