• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

How to pass two or more variables through 'header'

I am trying to figure out how to pass multiple variables through header.
Here's the code that I am trying right now.
page 1 -
$vars = "";
$error = 1;
    if($error) $vars .= "error=".$error;
    if($name) $vars .= "&name=".$name;
    if($desc) $vars .= "&desc=".$desc;
      
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location:newVariant.php?".$vars);

page 2-
$name = trim($_GET['name']);
$desc = trim($_GET['desc']);
$error = trim($_GET['error']);

echo $vars;

echo "test name = ";
echo $name;
echo " test desc = ";
echo $desc;
echo " test error = ";
echo $error
----------------------------
I can see the values in the url being passes as following:
xxxx/xxx/newVariant.php?vars=error=1&name=dfdfdfdfdf&desc=fdfdfdffd

But... the only value that is printing in my test is the error = 1, not sure why name and desc are not passing.

Any ideas?
0
awarraic
Asked:
awarraic
  • 3
  • 2
1 Solution
 
syedasimmeesaqCommented:
change the page1- line
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location:newVariant.php?".$vars);
 
to this

if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars");
and then on page-2 you need to get the value first like this

<? $vars = $_GET['vars']; ?>
0
 
awarraicAuthor Commented:
Sorry, didn't work.
Not getting any values in the $vars variable.
Here's what I have now.

Page 1-
$vars = "";
$error = 1;
    if($error) $vars .= "error=".$error;
    if($name) $vars .= "&amp;name=".$name;
    if($desc) $vars .= "&amp;desc=".$desc;
      
if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars");

page 2 -
$vars = $_GET['vars'];
echo $vars;

Here's the url - when I try to pass name = aa, and desc = bb.
/xxx/newVariant.php?vars=error=1&amp;name=aa&amp;desc=bb
0
 
syedasimmeesaqCommented:
try to pass name and desc separately and let me know what it does.

if ((!$name) or (!$desc) or (!$file_name1) or (!$file_name2)) header("location: newVariant.php?vars=$vars&name=$name&desc=$desc");
also on page 2

$vars = $_GET['vars'];
$name = $_GET['name'];
$desc = $_GET['desc'];
echo $vars;
echo $name;
echo desc;

thanks
echo $vars;

0
 
awarraicAuthor Commented:
Thank you sooo much. It's working great. Just curious why was my code not working if you 'd explain that 'll be great.

Thanks again.
0
 
syedasimmeesaqCommented:
you weren't sending the values in your page1 for those variables and also you weren't retrieving them on page 2.
Thank you for the points and glad to be of help
God bless you
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now