将php变量重定向到新网页+使用 [英] Redirecting php variables to new webpage + use

查看:85
本文介绍了将php变量重定向到新网页+使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的以下代码(php):

Here is my code below(php):

$answers = $_POST;

  $url1 = "http://www.example.com/page";

  $var1 = 12;  
  $var2 = 12;  
  $var3 = 8;  
  $var4 = 10;  
  $var5 = 4;  
  $var6 = 2;  
  $var7 = 1;  
  $var8 = 6;  
  $var9 = 12;   
  $var10 = 10;   
  $url2 = $url1.$var1.$var2.$var3.$var4.$var5.$var6.$var7.$var8.$var9.$var10;

  header("location:$url2");


用户将单击此站点,他们将被重定向到另一个页面.我正在尝试将这些变量转移到另一页.当前将变量显示为''.任何帮助将不胜感激:)


The users will click this site and they will be redirected to another page. I am trying to get these variables to be transfered to the other page. It is currently displaying the variable as ' ' . Any help would be greatly appreciated:)

推荐答案

假定您在能够运行PHP脚本的服务器上运行代码.将两个文件放在同一目录中.在我的本地主机上,我通过以下URL运行此脚本- http://localhost/test/page1.php

Aussuming that you running your code on server which is able to run PHP scripts. Keep both files in same directory. On my localhost I run this script by following url - http://localhost/test/page1.php

第一个文件代码(Page1.php)

<?php
    //this is page1.php
    $url1 = "page2.php";

    $var1 = 12;  
    $var2 = 12;  
    $var3 = 8;  
    $var4 = 10;  
    $var5 = 4;  
    $var6 = 2;  
    $var7 = 1;  
    $var8 = 6;  
    $var9 = 12;   
    $var10 = 10;   
    $url2 = $url1."?var1=".$var1."&var2=".$var2;

    header("location:$url2");

?>

第二个文件代码(page2.php)

<?php
    //this is page2.php
    $var1 = $_GET['var1'];
    echo "var 1 = ".$var1;
    echo "<br/>";
    $var2 = $_GET['var2'];
    echo "var 2 = ".$var2;

?>

您将被重定向到page2.php.

You will be redirected to page2.php.

这篇关于将php变量重定向到新网页+使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆