Forum

Thread tagged as: Question, Problem, Configuration

Lang Session not passing variable on page load

I have used the second example in the multilingual site documentation. Everything appears correct as I have implemented this in other sites, but with this build the session is not being passed on page load. Can this be a Server config problem?

Matthew Owen

Matthew Owen 0 points

  • 4 years ago

Ok appears to be fixed, all I changed was making sure all the pages are on the same level.

No it is not fixed. Anybody got any tips as to what could be causing the session to not be carried on load?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us what you're doing?

yes of course.

I am including the language session after perch at the top of the document.

   <?php
    session_start();
    $lang = 'de'; // default lang
    switch(perch_get('lang')) {
        case 'en':
            $lang = 'en';
            break;
        case 'de':
            $lang = 'de';
            break;
        // add more cases for language options here...

        default:
            if (isset($_SESSION['lang'])) {
                $lang = $_SESSION['lang'];
            }
            break;
    }
    $_SESSION['lang'] = $lang;
    ?>

Content is as documentation for second solution

<?php perch_content('Hotline - '.$lang); ?> 

Then I have page setting setup for page titles in eng/german

<?php if ($lang == 'en'){
include("inc/haupt-nav_en.php");
                    } else {
                        include("inc/haupt-nav_de.php");
                    }
                ?>

Here the english template

<?php 
    perch_pages_navigation(array(
     'levels'    => 1,
     'template' => array('en-item.html')
   ));
?>

here are the diagnostics

PERCH INFORMATION

Perch: 2.8.34
Production mode: Production (100)
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), perch_forms (1.8.3), perch_gallery (2.8.6)
DB driver: PDO
DB tables: perch2_categories (0), perch2_category_counts (0), perch2_category_sets (0), perch2_content_index (223), perch2_content_items (113), perch2_content_regions (39), perch2_navigation (3), perch2_navigation_pages (11), perch2_page_templates (1), perch2_pages (15), perch2_resource_log (124), perch2_resource_tags (0), perch2_resources (25), perch2_resources_to_tags (0), perch2_settings (16), perch2_user_passwords (0), perch2_user_privileges (26), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
PHPMailer: 5.2.21
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_gallery',
        'perch_forms',
    );
Editor plug-ins: markitup, ckeditor
H1: 5b17e503e68223bd18a14d7f2bc2f344
L1: a3ec9033b5231b0cf28a751e2f19b444
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
headerColour: #1a181d
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 1
content_collapseList: 1
lang: en-gb
update_2.8.34: done
latest_version: 2.8.15
on_sale_version: 2.8.34
headerScheme: dark
content_hideNonEditableRegions: 1
dashboard: 0
hide_pwd_reset: 0
content_frontend_edit: 0
logoPath: /perch/resources/logo-web-cms-1.jpg
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: db1062712-xxf1
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: db1062712-toro
PERCH_DB_PREFIX: perch2_
PERCH_TZ: Europe/Berlin
PERCH_EMAIL_FROM: iphone@sdb-grafik.de
PERCH_EMAIL_FROM_NAME: Matthew Owen
PERCH_LOGINPATH: /perch
PERCH_PATH: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch
PERCH_CORE: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch/core
PERCH_RESFILEPATH: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
HOSTING SETTINGS

PHP: 5.6.30-he.0
Zend: 2.6.0
OS: Linux
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
MySQL server: 5.6.34-79.1-log
Free disk space: 102.12 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, dba, dom, fileinfo, filter, hash, json, bz2, posix, Reflection, SPL, SimpleXML, session, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter, apache2handler, bcmath, zlib, calendar, ctype, curl, mbstring, ftp, gd, geoip, gettext, iconv, imap, intl, ldap, exif, mcrypt, mysqlnd, mysqli, mysql, PDO, pdo_mysql, pdo_sqlite, PDFlib, tet, pspell, shmop, soap, sockets, sqlite3, suhosin, tidy, timezonedb, wddx, xmlrpc, xsl, zip, Phar, mhash, ionCube Loader, Zend Guard Loader
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
HOME: /is/htdocs/wp1062712_5UZW3OW5K6/
USER: wp1062712
HTTP_HOST: lfgi.toro-evl.de
HTTP_X_REAL_IP: 217.95.92.198
HTTP_X_FORWARDED_FOR: 217.95.92.198
HTTP_CONNECTION: close
HTTP_COOKIE: PHPSESSID=pr4u04rf7vupmqfnq4en9272c3; cmsa=1
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8
HTTP_REFERER: https://lfgi.toro-evl.de/perch/core/settings/diagnostics/
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_ACCEPT_ENCODING: gzip, deflate
PATH: /bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin
SERVER_SOFTWARE: Apache
SERVER_NAME: lfgi.toro-evl.de
SERVER_ADDR: 127.0.0.56
SERVER_PORT: 80
REMOTE_ADDR: 217.95.92.198
DOCUMENT_ROOT: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/
REQUEST_SCHEME: http
CONTEXT_DOCUMENT_ROOT: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/
SERVER_ADMIN: info@studio141.de
SCRIPT_FILENAME: /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 56700
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.0
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1489745176.203
REQUEST_TIME: 1489745176
argc: 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which is the part that isn't working?

it's actually all working. By page load it reverts back to 'de'. That is my worry. Why is the session variable not being passed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

From one page load to the next, or after the session expires?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you doing this before any HTML is output?

Yes, the session is being called right after the Perch call.

<?php include('perch/runtime.php'); ?>
<?php include('inc/language-session.php');?>
<!doctype html>
<head>
<meta charset="utf-8" />

The Dev Site is Online actually: here

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you add this to the bottom of language-session.php what does it output?

print_r($_SESSION);

Hi Drew, other than breaking the layout it is writing the selected 'lang' in the top left hand corner.

I am using a master page which has this at the top:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>
<?php include('inc/language-session.php');?>
<!doctype html>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me exactly what is output? The detail matters.

do mean with debug turned on....

Here is what I am getting in the front end:

Debug Message
[1] SELECT * FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
Using template: /templates/pages/attributes/seo.html
[13] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/index.php' OR regionPage='*' ORDER BY regionPage DESC
[3] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
[1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-002', '000') ORDER BY pageTreePosition DESC
[3] Using template: /templates/navigation/item.html
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='leistungen-menu' LIMIT 1
[1] SELECT np.pageID, np.pageParentID, np.pageDepth, np.pageTreePosition FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND (p.pagePath='/leistungen' OR p.pageSortPath='/leistungen') LIMIT 1
[7] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/index.php' LIMIT 1
[7] Using template: /templates/navigation/de-sub-menu.html
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='angestellte-menu' LIMIT 1
[1] SELECT np.pageID, np.pageParentID, np.pageDepth, np.pageTreePosition FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND (p.pagePath='/leistungen' OR p.pageSortPath='/leistungen') LIMIT 1
[1] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/index.php' LIMIT 1
[1] Using template: /templates/navigation/de-sub-menu.html
[1] SELECT groupID FROM perch2_navigation WHERE groupSlug='kunden-menu' LIMIT 1
[1] SELECT np.pageID, np.pageParentID, np.pageDepth, np.pageTreePosition FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=3 AND (p.pagePath='/leistungen' OR p.pageSortPath='/leistungen') LIMIT 1
[2] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=3 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=3 AND p.pagePath='/index.php' LIMIT 1
[2] Using template: /templates/navigation/de-sub-menu.html
Array
(
    [type] => 8
    [message] => Undefined variable: lang
    [file] => /is/htdocs/wp1062712_5UZW3OW5K6/lfgi/perch/templates/layouts/footer.php
    [line] => 3
)

I am also now getting this:

Array ( [ready] => 1 [userID] => 1 [userHash] => c27d9cb771b45d283a5fea2a2c1eca45 [content_expand_list] => Array ( [0] => 0 ) [csrf_token] => fb3732294c200f7a1df86e543224a46b [lang] => de )

Ok I think I may have found the problem. I am using a layout footer with the following code:

<div class="footer">
    Copyright © TORO Eventservices GmbH • <a href="<?php perch_content('Impressum - '.$lang); ?>">Impressum</a> • <a href="<?php perch_content('Arbeitnehmerueberlassung - '.$lang); ?>" target="_blank">Arbeitnehmerüberlassung</a>
</div>

The perch content is only being used for the links to other pages, in the back end, unlike all the other perch content it is only giving me one content field (content name -) not two (content name - de / content name -en).

Maybe I need to rethink how I am doing the footer layout...

Yes that appears to be it.

I have dropped the layout include, added a perch Content field and now all works as should.

Thank you Drew for prodding me in the right direction! Happy Monday to you!