468,251 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,251 developers. It's quick & easy.

Pass Variable to another script

I need to pass a variable from script1.php to script2.php. The problem
is that these scripts use frames and therefore I am able to pass the
variable through the URL. It also does not use forms to set this
variable, so i cannot pass it this way either.

So to simplify I have :

script1.php
<?php
$var1 = value;
echo '<href="script2.php">link to script2</a>';
?>

script2.php

<?php
echo $var1;
?>

How can script2 find this value?

Jun 5 '06 #1
1 7426
If you don't want to pass the variable through a get or post, try using
a session variable. The code would look something like:
script 1:
session_start();
$_SESSION['var1'] = 'test';

script 2:
session_start();
echo $_SESSION['var1'];

But it would be cleaner if you passed the variable in your link to the
other file like this:
script 1:
$var1 = 'test';
echo '<href="script2.php?var1=$var1">link to script2</a>';
script 2:
$var1 = $_GET['var1'];
echo $var1;

You could also send it via a form with POST by using hidden fields.
Let me know if you need any further advice.
Jon Tjemsland

drec wrote:
I need to pass a variable from script1.php to script2.php. The problem
is that these scripts use frames and therefore I am able to pass the
variable through the URL. It also does not use forms to set this
variable, so i cannot pass it this way either.

So to simplify I have :

script1.php
<?php
$var1 = value;
echo '<href="script2.php">link to script2</a>';
?>

script2.php

<?php
echo $var1; ?>

How can script2 find this value?


Jun 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by krunkelgarten | last post: by
1 post views Thread by Steve | last post: by
2 posts views Thread by Augusto Cesar | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.