dongqindu8110 2014-02-21 00:49
浏览 91
已采纳

如何在PHP中的页面之间传输变量?

I am trying to make a login form with PHP, and I want to get a value from a form like so:

$name = $_POST["name"];
$email = $_POST["email"];

then, when the user clicks "Submit", I want the new page to have access to these variables. Using the

include 'file1.php';

technically works, but I dont want ALL of 'file1.php', just the variables. Any Suggestions?

  • 写回答

2条回答 默认 最新

  • drd94483 2014-02-21 05:11
    关注

    You have to use session. Here is a simple demonstration:


    page1.php - Load page one to set the session variable
    <?php
    // begin the session
    session_start(); 
    
    // set the value of the session variable 'foo'
    $_SESSION['foo']='bar'; 
    
    // echo a little message to say it is done
    echo 'Setting value of foo'; 
    ?>
    


    page2.php - Load page two and it will have access to the session variable you set in page1.php

    <?php 
    // begin our session
    session_start(); 
    
    // echo the session variable
    echo 'The value of foo is '.$_SESSION['foo']; 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向