-1

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:)

1 Answers1

-1

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

First File Code (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");

?>

Second file code (page2.php)

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

?>

You will be redirected to page2.php.

Developer
  • 324
  • 3
  • 13
  • 1
    Did you read this in the question? *"It is currently displaying the variable as ' '"* – Funk Forty Niner Sep 29 '16 at 13:57
  • I'm not damn sure but I think Without '?' query string variables will not get parsed. – Developer Sep 29 '16 at 14:00
  • even without that, the OP gets `''`. POST/GET doesn't matter; they're getting empty `''` and they will get parsed if a webserver/php is installed and using the right URL and not a `file:///`. – Funk Forty Niner Sep 29 '16 at 14:01
  • I think OP needs to add code of second page, how he is trying to get variables – Developer Sep 29 '16 at 14:04
  • @Fred-ii- I added this piece of code to my code and unfortunately, I got the same output as before, a single space. Thank you for the suggestion. – chicken_wangs18 Sep 29 '16 at 15:31
  • Assuming that you are running script on server which is able to run PHP script... Just last suggestion and i will be out... ;-) try edited code – Developer Sep 29 '16 at 16:05