PHP保存变量

Jam*_*mes 5 php arrays variables submit

有一个$variable,它的价值很大Array().

它是在页面内创建function one() { ... }first.php.

first.phpmethod="post"在子页面重新加载后有表单second.php

有没有什么办法让价值$variable里面function two() { ... }second.php

似乎我可以$variable在表单内发布值,问题是它可以包含超过千个符号.

谢谢.

Kno*_*ing 4

session_start()在任何 PHP 网页的开头使用“ ”函数,就在第一个 PHP 开始标记 ( <?php) 之后。

然后将您的变量存储到超全局会话数组变量中,在“first.php”页面中,例如:-

<?php
session_start(); // This line must be at the very beginning of this PHP page.

function one() {
    // blah, blah, ...

    if(isset($variable) && !empty($variable)) {
        $_SESSION['customVariable'] = $variable;
    }

    // some more blah, blah, ...
}
?>
Run Code Online (Sandbox Code Playgroud)

现在,如果您来到“second.php”页面,您需要访问该页面的功能:-

<?php
function two() {
    // if any blah, blah, ...

    if(isset($_SESSION['customVariable']) && !empty($_SESSION['customVariable'])) {
        $variable = $_SESSION['customVariable'];
    }

    // next series of blah, blah, ...
}
?>
Run Code Online (Sandbox Code Playgroud)

但在这个“second.php”页面中,“ session_start()”函数必须写在该页面的最开头,紧接在第一个 PHP 开始标记之后。

希望能帮助到你。