Pass a variable value from one php page to another

我只是一个虾纸丫 提交于 2019-12-10 11:33:18

问题


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

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:

$sendto="value";

How can I achieve this?

EDIT: Apparently this requires more information.


回答1:


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.

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

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



回答2:


Either POST your value so your second page can retrieve it in the $_POST array, or include it in the URL path so your second page can $_GET it.

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



来源:https://stackoverflow.com/questions/18516390/pass-a-variable-value-from-one-php-page-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!