Jump to content

I to process form variables when register_globals = off


Trium918

Recommended Posts

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.";
  }
  
?>

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.