Page 1 of 1

problem passing variables to a sec. php script

Posted: Fri Aug 30, 2002 9:08 pm
by robin1
Hi everybody,
problem... passing a variable to a sec. php script but as the code is executed the variable in the sec. script is changed. would like to keep the variable the same no matter what takes place in the sec script.

program1.php
<?
<a href="<?php echo"phpcode.php?cmd1=$info1";?>">
?>

phpcode.php
<?
$variable1 = $cmd1; \\ this part works
\\but as the code cont. the $variable1 gets changed..the above line is the first line in the code.. need to keep this variable constant, how is this done after receiving the variable from the program1.php...
?>

Posted: Fri Aug 30, 2002 9:22 pm
by gotDNS
First of all, ur code there is....yes well, here....program1.php:

Code: Select all

<?php
echo "<a href='phpcode.php?cmd1=$info1'>";
?>
Sec. php script:

Code: Select all

<?php
$_GET&#1111;'cmd1'];
$variable1 = $cmd1;
?>

Re: problem passing variables to a sec. php script

Posted: Sun Sep 01, 2002 3:07 am
by gite_ashish
Hi,

If don't want some of your values to change during program execution, you can use define(). See php man for details http://www.php.net/manual/en/language.constants.html

Code: Select all

&lt;?php

    // this is sec. php

    define( 'var1', $_GET&#1111;cmd1] );

    echo 'cmd1: ' . $_GET&#1111;cmd1] . '&lt;BR&gt;';
    echo 'var1: ' . var1 . '&lt;P&gt;';

    $_GET&#1111;cmd1] .= ' and text2';

    // uncommenting following will generate parser error
    // var1 .= ' hi !';

    echo 'cmd1: ' . $_GET&#1111;cmd1] . '&lt;BR&gt;';
    echo 'var1: ' . var1 . '&lt;P&gt;';

?&gt;
All the best,