Jump to content

passing vareabls in links?


knowram

Recommended Posts

I am trying to create a back button on a form. would like to be able to send the variable $_REQUSET to the page that I am going back to. However I don't know what is used in that array to divide variables. so when I try to print it on the page that I am going back to all i get is  "ARRAY". here is the code that I am using
the like is:
[code]
<a href="diagnoses.php?backinfo=<?=$_REQUEST?>">Back To Diagnoses</a>
[/code]
diagnoses.php being the previous page that I am trying to go back to.
and the cod for on the diagnoses.php page to see if the info has been submitted and I can get to it is:
[code]
echo'<pre>';
print_r ($backinfo);
echo '</pre>';
[/code]
I have been able to submit arrays through links like this before but they have always been arrays that I have made so I have known how to split them up on the following page.

dose this make any sense? If so have any ideas?
Link to comment
Share on other sites

The $_REQUEST var is an array of all $_GET and $_POST and $_SESSION variables.
The good way to pass all this vars from the array is to seperate them and putting
them into the $_POST array

[code]
<?php
foreach($_REQUEST as $key => $val) {
  $_POST[$key] = $val;
}
?>

<a href="diagnoses.php">Back To Diagnoses</a>
[/code]

Or you could pass them by $_GET aswell
[code]
<?php
$var_get = "?";
foreach($_REQUEST as $key => $val) {
  if($var_get != "?") {
    $var_get .= "&";
  }
  $var_get .= "$key=$val";
}
?>

<a href='diagnoses.php<?php echo "$var_get"; ?>'>Back To Diagnoses</a>
[/code]

Then on the next (or previous) page you can simply catch them again by the var $_REQUEST.
Link to comment
Share on other sites

You could [url=http://php.net/serialize]serialize[/url] the array, put it in the link and then [url=http://php.net/unserialize]unserialize[/url] at the other page.

Example:
[code]
<?php
$data = serialize($_REQUEST);
echo "<a href='what-ever-page.php?data={$data}'>Back</a>";
?>
[/code]
(If you'd like to use POST or GET instead of REQUEST you just replace it)

Another solution would be to use [url=http://php.net/http_build_query]http_build_query[/url] to build a query string automaticly for you. You need to use PHP5 though.
Example:
[code]
<?php
$data = http_build_query($_REQUEST);
echo "<a href='what-ever-page.php?{$data}'>Back</a>";
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.