problem passing variables to a sec. php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

problem passing variables to a sec. php script

Post 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...
?>
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post 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;
?>
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Re: problem passing variables to a sec. php script

Post 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,
Post Reply