简体   繁体   English

在页面之间传递php变量

[英]Pass php Variables between pages

I am trying to pass variables from a form to a website page.我正在尝试将变量从表单传递到网站页面。 Here is the guide that I am following: https://www.jotform.com/help/213-Send-POST-Data-From-JotForm-Using-PHP-in-Custom-Thank-You-Page这是我遵循的指南: https : //www.jotform.com/help/213-Send-POST-Data-From-JotForm-Using-PHP-in-Custom-Thank-You-Page

Here is the code on my redirect.php page:这是我的 redirect.php 页面上的代码:

   <?php
     $answers = $_POST;
      $url1 = "http://www.example.com/results";

      $var1 = "?user_email =".urlencode($answers[user_email]);
      $var2 = "&input_63 =".urlencode($answers[input_63]);
      $var3 = "&input_64 =".urlencode($answers[input_64]);
      $var4 = "&input_65 =".urlencode($answers[input_65]);
      $var5 = "&input_66 =".urlencode($answers[input_66]);
      $var6 = "&input_67 =".urlencode($answers[input_67]);
      $var7 = "&input_68 =".urlencode($answers[input_68]);
      $var8 = "&input_69 =".urlencode($answers[input_69]);
      $var9 = "&input_70 =".urlencode($answers[input_71]);
      $var10 = "&input_71 =".urlencode($answers[input_71]);
      $var11 = "&input_55 =".urlencode($answers[input_55]);
      $var12 = "&input_56 =".urlencode($answers[input_56]);
      $var13 = "&input_57 =".urlencode($answers[input_57]);
      $url2=$url1.$var1.$var2.$var3.$var4.$var5.$var6.$var7.$var8.$var9.$var10.$var11.$var12.$var13;
      header("location:$url2");
    ?>

The variables show up on the page as ' '.变量在页面上显示为“ ”。

I have no clue what to do and help would be greatly appreciated.我不知道该怎么做,我们将不胜感激。

If you are able to change the input names into an array then it is much simpler.如果您能够将输入名称更改为数组,那么它就简单得多。 If not, then you can pass the data several ways.如果没有,那么您可以通过多种方式传递数据。 Using a session:使用会话:

session_start();
$_SESSION['answers'] = $_POST;
header("location: $url1");

Then on the next page:然后在下一页:

session_start();
$answers = $_SESSION['answers'];
echo $answers['user_email'];

I wouldn't do it, but if you insist on the URL method, then this is far easier:我不会这样做,但是如果您坚持使用 URL 方法,那么这要容易得多:

$query = http_build_query($_POST);
header("location: $url1?$query");

http_build_query() will URL encode and build the string. http_build_query()将 URL 编码并构建字符串。

TO pass variables from a form to a php page in php is rather simple在 php 中将变量从表单传递到 php 页面相当简单

First your form首先你的表格

<form method="POST" action="page_to_send_data_to.php">
  <input type="" name="something" value=""></input>
  <input type="" name="somethingelse" value=""></input>
  <input type="submit"></input>
</form>

Then on the page you submit to然后在您提交的页面上

<?php 
if(!isset($_POST['something']) {
    $var1 = $_POST['something'];
    $var2 = $_POST['something'];
}
echo $var1.' '.$var2;
?>

Your url is probably corrupted because of spaces, you don't set input_63 to anything because you end with a space, you set input_63_ (with an underscore, spaces are converted to underscore by php's parsing logic), which i bet isn't what you're looking for in the following script.您的网址可能因空格而损坏,您没有将input_63设置为任何内容,因为您以空格结尾,您设置了input_63_ (带有下划线,空格被 php 的解析逻辑转换为下划线),我敢打赌这不是什么您正在以下脚本中查找。 and stop making your queries manually, for the vast majority of cases, you should use http_build_query instead.并停止手动进行查询,对于绝大多数情况,您应该改用 http_build_query。 like喜欢

$url2=$url1.'?'.http_build_query(array('input63'=>$answers[input_63],'input_64'=>$answers[input_64]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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