By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Variable

P: n/a
dis is appu

plz help me

How to call the one php file variable to another php file........

May 15 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ja*******@gmail.com schreef:
dis is appu

plz help me

How to call the one php file variable to another php file........
/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, 'works' here means that the variables
* $varone and $vartwo are available within the include()ed file. */

/* Won't work; file.txt wasn't handled by someserver. */
include ("http://someserver/file.txt?varone=1&vartwo=2");

/* Won't work; looks for a file named 'file.php?varone=1&vartwo=2'
* on the local filesystem. */
include ("file.php?varone=1&vartwo=2");

/* Works. */
include ("http://someserver/file.php?varone=1&vartwo=2");

$varone = 1;
$vartwo = 2;
include ("file.txt"); /* Works. */
include ("file.php"); /* Works. */

--
Arjen
http://www.hondenpage.com
May 15 '07 #2

P: n/a
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.
May 15 '07 #3

P: n/a
ja*******@gmail.com wrote:
dis is appu

plz help me

How to call the one php file variable to another php file........
Do you mean within the same web page, or on a new web page? If the
latter, you need to use sessions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.