简体   繁体   中英

Passing variables between PHP scripts

I have problem and can not understand why this not working. The language not transferred and I see empty area.

In my PHP:

<?php
$_SESSION['Language']   = $_GET['Spanish'];
header("Location:../index.php");
exit;
?>

In index.php:

<?php

    $Language   = $_SESSION['Language'];


    include 'header.php';

    echo '<div id="content"> 
            <img src="Images/SplashScreen.jpg" id="bgImage" alt="City" width="1280" height="720" />
                <div class="splashOuterRingsOverlay" id="contain">
                    <img src="Images/Loading-outer-circle.png" id="image1" alt="inner ring" width="282" height="282">
                </div>
                <div class="splashInnerRingsOverlay" id="contain">
                    <img src="Images/Loading-inner-circle.png" id="image2" alt="outer ring" width="282" height="282">
                </div>
                <div class="splashButtonOverlay">
                    <!--<button type="button" id="splashButton" onclick="loadData(20)"></button>-->
                    <button type="button" id="splashButton" onclick="loadLangCustom(\'Spanish\')"></button>
                </div>
                <div class="splashTitleOverlay">
                    <p id="splashTitle">'.$Language.'</p>
                    <!--<p id="splashTitle">Please press BERMAD icon</p>-->
                </div>
        </div>';

    include 'footer.php';
?>

If you set the session variable you have to add the session_start at the top of the php page.

session_start()

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Change your code like this

    <?php
    session_start();
if (isset( $_GET['Spanish'])) {
    $_SESSION['Language']   = $_GET['Spanish'];
    header("Location:../index.php");
    exit;
}

    ?>

Add session_start() in the beginning of your code

--

<?php
session_start();
$_SESSION['Language']   = $_GET['Spanish'];




<?php
session_start();
$Language   = $_SESSION['Language'];

您在index.phpmy.php中缺少session_start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM