Welcome to WebmasterWorld Guest from 54.197.90.95

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Work around for global_variables=off

how to declare variable when global vars is off

     
12:52 am on Aug 23, 2003 (gmt 0)

New User

10+ Year Member

joined:June 19, 2003
posts:10
votes: 0


I turned global variables off in php.ini

I know have the following problem with my forms.
This is what i see in my text boxes. <?=$varname?> instead of the value of the variable. Does anyone know how to fix this, do i need to declare the variable before i use it, if so how do i do this?

thanx

2:00 am on Aug 23, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Mar 20, 2003
posts:390
votes: 0


If register_globals is off, you'll have to use predefined superglobals to get the variables you need to fill the form.

$varname=$_GET['varname'];
$varname=$_POST['varname'];

and then echo $varname, or just

echo $_GET['varname'];
echo $_POST['varname'];

There's no reason you should see PHP (<?=$varname?>) in HTML, though. If those variables are empty, the fields should just be blank. Check your code or post more of it here.

9:04 am on Aug 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:July 24, 2002
posts:1124
votes: 0


might it be 'cos short tags <?> are not activated in your php.ini?

try <?php echo $variable;?>

4:12 pm on Aug 23, 2003 (gmt 0)

New User

10+ Year Member

joined:June 19, 2003
posts:10
votes: 0


Thanks Dolemite
$varname = $_POST['varname'] solved my problem.

Jamie,
I did not have short tags turned on in php.ini, thanks

6:44 pm on Aug 23, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


another useful function is extract [ca.php.net]
11:57 am on Aug 24, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Regarding the register_globals directive:
"Perhaps the most controversial change in PHP is when
the default value for the PHP directive register_globals went
from ON to OFF in PHP 4.2.0."

I actually prefer register_globals off and the PHP manual recommends this practice for security purposes (the directive itself isn't insecure but rather it's the misuse of it). [us3.php.net]

If you have a shared server and you're hosting provider has register_globals on, you can set yourself up by adding an .htaccess file to your php code directories with a single line to turn the register_globals off:

php_flag register_globals off

You'll have to modify your code though, just as described earlier in this post.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members