p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: A solution to your register_globals woes:


Message #1 by "Nikolai Devereaux" <yomama@u...> on Wed, 29 May 2002 17:29:16 -0700
There's a million ways to get around the register_globals = off problem.
Here's one way:

---- register_globals.inc ----
<?php

// pass in $_GET or $_POST here:
function register_globals(&$form_array)
{
   foreach($form_array as $name => $value)
   {
       $GLOBALS[$name] = $value;
   }
}

?>
--------------------------------

Your code then would include* this file, then register all your _GET or
_POST vars as globals, and you can be happy.

*  (or require, or include_once, or require_once.  your choice.  i prefer
require_once)


Here's your code, patched:

<HTML>
<HEAD></HEAD>
<BODY>
<B>Namllu Credit Bank Loan Application Form</B>
<BR>
<BR>
<?
require_once('register_globals.inc');
register_globals($_GET);

$SalaryAllowance = $Salary/5;
$AgeAllowance = ($Age/10 - ($Age%10)/10)-1;
$LoanAllowance = $SalaryAllowance * $AgeAllowance;
echo "Loan wanted:$Loan<BR>";
echo "Loan amount we will allow:$LoanAllowance<BR><BR>";
if ($Loan <= $LoanAllowance) echo "Yes, $FirstName $LastName, we are
delighted to accept your application";
if ($Loan > $LoanAllowance) echo "Sorry, $FirstName $LastName, we cannot
accept your application at this time";
?>
</BODY>
</HTML>


take care,

nik

Message #2 by skynautjunk@y... on Thu, 30 May 2002 04:21:33
Thanks!
I was having similar problems.
Additionally, I found the following article provided a nice explanation.

http://www.webmasterbase.com/article/758
---

  Return to Index