将一个变量值从一个 php 页面传递到另一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18516390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:42:10  来源:igfitidea点击:

Pass a variable value from one php page to another

phpvariablessession-variables

提问by KingLouie

I'm trying to send the value of this php get_field variable from a wordpress Archive page.

我正在尝试从 wordpress 存档页面发送这个 php get_field 变量的值。

get_field('supplier_email_address', 'product_brand_' . $term->term_id );

get_field('supplier_email_address', 'product_brand_' . $term->term_id );

to another sendmessage.php page which is never accessed other than with the of JS to send a form. The variable I need filled is called:

到另一个 sendmessage.php 页面,除了使用 JS 发送表单外,从未访问过该页面。我需要填充的变量称为:

$sendto="value";

$sendto="value";

How can I achieve this?

我怎样才能做到这一点?

EDIT: Apparently this requires more information.

编辑:显然这需要更多信息。

回答by Nambi

Use session variables.

使用会话变量。

First of all every page you want to use sessions on needs to have the function session_start(); declared at the top of every page. You then can use the session superglobal to store things.

首先,您要使用会话的每个页面都需要具有函数 session_start(); 在每一页的顶部声明。然后你可以使用会话超全局来存储东西。

Pg1.php:
    <?php
    session_start();
    $_SESSION['variable_name'] = 'string';
    ?>

Pg2.php:
    <?php
    session_start();
    echo $_SESSION['variable_name'];
    ?>
Pg2.php will show: some string

回答by ChunkyBaconPlz

Either POSTyour value so your second page can retrieve it in the $_POSTarray, or include it in the URL path so your second page can $_GETit.

要么是POST您的值,以便您的第二页可以在$_POST数组中检索它,要么将其包含在 URL 路径中,以便您的第二页可以使用$_GET它。

Without more info, we can't really help you any more than that.

如果没有更多信息,我们真的无法为您提供更多帮助。