Trium918 Posted March 21, 2007 Share Posted March 21, 2007 Correct me if I am wrong, but if register_globals = off then php will not process $name and $password variables from a form, how do I process these variables from a form. When I set the configuration variable named register_globals = On in the php.ini file then the code below works just fine, but how do I get the code working when its Off. <? if(!isset($name)&&!isset($password)) { //Visitor needs to enter a name and password ?> <h1>Please Log In</h1> This page is secret. <form method = post > <table border = 1> <tr> <th> Username </th> <td> <input type = text name = name> </td> </tr> <tr> <th> Password </th> <td> <input type = password name = password> </td> </tr> <tr> <td colspan =2 align = center> <input type = submit value = "Log In"> </td> </tr> </form> <? } else if($name=="user"&&$password=="pass") { // visitor's name and password combination are correct echo "<h1>Here it is!</h1>"; echo "I bet you are glad you can see this secret page."; } else { // visitor's name and password combination are not correct echo "<h1>Go Away!</h1>"; echo "You are not authorized to view this resource."; } ?> Link to comment https://forums.phpfreaks.com/topic/43703-i-to-process-form-variables-when-register_globals-off/ Share on other sites More sharing options...
kenrbnsn Posted March 21, 2007 Share Posted March 21, 2007 When register_globals is off (as it should be), you need to retrieve the values directly from either the $_GET or $_POST superglobal arrays, depending on how the form is set up. In your case, you would use the $_POST array: <?php if(!isset($_POST['name'])&&!isset($_POST['password'])) { //Visitor needs to enter a name and password ?> <h1>Please Log In</h1> This page is secret. <form method = "post" > <table border = 1> <tr> <th> Username </th> <td> <input type = "text" name = "name"> </td> </tr> <tr> <th> Password </th> <td> <input type = "password" name = "password"> </td> </tr> <tr> <td colspan ="2" align = "center"> <input type = "submit" value = "Log In"> </td> </tr> </form> <? } else if($_POST['name']=="user"&&$_POST['password']=="pass") { // visitor's name and password combination are correct echo "<h1>Here it is!</h1>"; echo "I bet you are glad you can see this secret page."; } else { // visitor's name and password combination are not correct echo "<h1>Go Away!</h1>"; echo "You are not authorized to view this resource."; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/43703-i-to-process-form-variables-when-register_globals-off/#findComment-212172 Share on other sites More sharing options...
Trium918 Posted March 21, 2007 Author Share Posted March 21, 2007 When should I use the $_GET superglobal variable? Link to comment https://forums.phpfreaks.com/topic/43703-i-to-process-form-variables-when-register_globals-off/#findComment-212174 Share on other sites More sharing options...
kenrbnsn Posted March 21, 2007 Share Posted March 21, 2007 You use the $_GET array to get the values from the URL and when the form uses 'method="get"'. Ken Link to comment https://forums.phpfreaks.com/topic/43703-i-to-process-form-variables-when-register_globals-off/#findComment-212185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.