PHP values ​​inside arrays in a PHP file display an error when this file is called via Ajax!

I call the php file as follows using Fancybox

index.php:

<div class="pic">
            <a id="showcase1" href="showcase/showcase1.php"><img src="images/showcase1t.png"/></a>
        </div><!-- .pic -->

inside showcase/showcase1.phpI have the following code:

<?php include_once '../localization.php'; ?>
<div id="inline">
    <img src="images/showcase2.png"/>
    <?php echo l('inline_p'); ?>
    <a href="http://studyatbest.com"><?php echo l('inline_a'); ?></a>
</div>

which calls the values ​​inside the array from the language file ( lang.en.php):

'inline_p' => ' <p><strong>Previous</strong> = Left Arrow Key</p>
                <p><strong>Next</strong> = Right Arrow Key</p>
                <p><strong>Close</strong> = Esc</p>',
'inline_a' => 'Visit',

helps the "controller" ( localization.php):

<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang'])) {
    $lang = $_GET['lang'];

    // register the session and set the cookie
    $_SESSION['lang'] = $lang;
    setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang'])) {
    $lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang'])) {
    $lang = $_COOKIE['lang'];
}
else {
    $lang = 'en';
}

// use appropiate lang.xx.php file according to the value of the $lang
switch ($lang) {
case 'en':
    $lang_file = 'lang.en.php';
    break;

case 'es':
    $lang_file = 'lang.es.php';
    break;

case 'zh-tw':
    $lang_file = 'lang.zh-tw.php';
    break;

case 'zh-cn':
    $lang_file = 'lang.zh-cn.php';
    break;

default:
    $lang_file = 'lang.en.php';
}

//translation helper function
function l($localization) {
    global $lang;
    return $lang[$localization];
}

    include_once 'languages/'.$lang_file;
?>

The matrix perfectly displays the values ​​in the language files if I open it directly showcase/showcase1.php, but when it is called from the binding using fancybox, it says:

Fatal error: call undefined function l () in D: \ WAMP \ WWW \ projects \ alexchen \ alexchen2.6 \ showcase \ showcase1.php on line 3

Any suggestions?

: l - , (. localization.php).

+3
4

require_once . , localisation.php.

, , . , require over include.

AJAX , ?

+1

. localization.php langauages/lang.en.php showcase/showcase1.php, PHP- . , . , !

+1

, , , localization.php showcase1.php. AJAX, , , fancybox php. Firebug live http headers Firefox, , showcase1.php.

0

error_reporting (E_ALL); . , localization.php, - . display_errors php.ini ini_set().

, script AJAX. Fiddler.

0

Source: https://habr.com/ru/post/1754417/


All Articles