LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Another register_globals question (https://www.linuxquestions.org/questions/programming-9/another-register_globals-question-64615/)

raypen 06-09-2003 05:16 PM

Another register_globals question
 
I thought I understood the implications of setting
register_globals to off, but further study has got me
somewhat confused. Although I have read this dicsussion
of this topic on the PHP website:

http://www.php.net/manual/en/printwn...terglobals.php

I have run across a problem which I can't seem to fathom.

The simple script below works to demonstrate the use of
global variables:

<html>
<body>

<?php

function showform() {
global $variable1, $proof;
$proof='<hr>Proof Of Concept!';
echo '<form method="get">';
echo '<hr>';
echo '<input type="text" size="25" name="variable1"
value="'.$variable1.'">';
echo '<br>';
echo '<input type="submit" value="TESTME!">';
echo '</form>';

if ( isset($variable1) ) {
// if it DOES exist
echo $variable1.'<br>';
}
else {
// if it does NOT exist
echo 'Missing $variable1<br>';
}

showform();

// I threw this in to illustrate a point I made earlier while
// rambling...
echo $proof;

?>

</body>
</html>

The statement 'Missing $variable1' always prints before the
form appears and "Proof of Concept' appears
just below the form when 'echo $proof;' is encountered.

However, I can't enter anything in the form to set $variable1;
'Missing $variable1' still appears even if I use:

if ( isset($_GET['variable1']) )

Apparently, the variable is not being set.

1. Why isn't the variable set?

2. Why does echo $proof work when I should be using
echo $_GET['proof']; if register_globals is off?

I seem to be missing something, but I think it is fundamental
to my understanding of how variables work.

TIA

j-ray 06-12-2003 07:04 AM

your form does not contain an action tag
<form action="script.php" method="...
maybe that's all
cheers, jens


All times are GMT -5. The time now is 07:38 PM.