|
Posted by Schraalhans Keukenmeester on 05/15/07 09:34
At Tue, 15 May 2007 01:42:02 -0700, java.inet let his monkeys type:
> dis is appu
>
> plz help me
>
> How to call the one php file variable to another php file........
Arjen just gave you a solution for when you want to include a file in
another with variables parsed to it. If what you want is variables
keeping their values after (e.g.) clicking a link on the first page, which
opens a second...
You can do it the unsafe & dirty way:
(PS I left out all the proper html tags that a page should have)
<?PHP
//script 1
$myvar = "Hello World!";
$_GET['myvar'] = $myvar;
// or $_POST['myvar'] = $myvar;
?>
<a href='script2.php'>Click!</a>
or
<?PHP
//script 1
$myvar = "Hello World!";
echo "<a href='script2.php?myvar=$myvar'>Click!</a>";
?>
<?PHP
//script 2
echo $_REQUEST['myvar'];
// or $_GET/$_POST, whichever you used
?>
Or you do it the safe and sound way:
<?PHP
//script 1
session_start();
$myvar="Hello Safe World!";
$_SESSION['myvar'] = $myvar;
?>
<a href='script2.php'>Click!</a>
<?PHP
//script 2
session_start();
if (isset($_SESSION['myvar']) {
$myvar = $_SESSION['myvar'];
echo $myvar;
}
session_destroy();
unset($_SESSION);
?>
The former method is vulnerable to attacks. Anyone calling the script like
so:
http://www.yourserver.com/script2.php?myvar=hackedvalue
might mess up your program.
There's also the possibility to use forms with hidden fields to get
variables across, this basically sets $_GET or $_POST avriables similar to
the first example.
HTH
Sh.
Navigation:
[Reply to this message]
|