I am using the Beginning PHP4 book. The book does not explain coding with the now default "register_globals = Off." The explanation in the php.ini was enough of a warning
Quote:
quote:; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off
|
for me to resist the urge to set the setting to "On."
Starting in chapter 3, the code examples would not work. This chapter is the introduction of introducing variables from user input for processing by your php code. I did not want to put the book on the bookshelf to gather dust. After many Google searches and reading articles here, I was still confused as I am an ignorant beginning programmer. Ignorant in the sense that I have no knowledge in computer programming experience or theory. I left the book on my desk but started to persue JavaScript and Python in hopes that something I learned from exposure to those languages would help me with php. The end result is that I have a better comprehension of the posts on this forum and other mediums. Although I am still in the infancy of my PHP understanding, the examples in chapter 3 now work, even with the register_globals off.
Here is the code for each example in Chapter 3. The code is listed by page number. Only the code examples that do the processing are listed as the code examples that the user interacts with are fine. I am using php-4.3.8, apache_2.0.50 on a Windows 2000 machine. One word on my code, I code my web documents to the XHTML1.0 standard, so make sure that in your php.ini file that short_open_tags are off:
Quote:
quote:; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off
|
Now for the code to chapter 3 using the php.ini setting: register_globals = Off
Page 77 - text.php:
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>text.php</title>
</head>
<body>
Your favorite author is:
<?php
$Author = $_GET['Author'];
echo $Author;
?>
</body>
</html>
Page 81 - textarea.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>textarea.php</title>
</head>
<body>
Your favorite web sites are:
<br />
<?php
$Websites = $_POST['Websites'];
echo $Websites;
?>
</body>
</html>
Page 83 - checkbox.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>checkbox.php</title>
</head>
<body>
<?php
$Choice = $_POST['Choice'];
echo $Choice;
?>
</body>
</html>
Page 86 - checkboxes.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>checkboxes.php</title>
</head>
<body>
<?php
$Choice1 = $_POST['Choice1'];
$Choice2 = $_POST['Choice2'];
$Choice3 = $_POST['Choice3'];
echo "$Choice1<br />";
echo "$Choice2<br />";
echo "$Choice3<br />";
?>
</body>
</html>
Page 89 - radio.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>radio.php</title>
</head>
<body>
<?php
$Question1 = $_GET['Question1'];
echo "You selected the answer: $Question1";
?>
</body>
</html>
Page 93 - listbox.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>listbox.php</title>
</head>
<body>
<?php
$EngineSize = $_GET['EngineSize'];
$Price = $_GET['Price'];
echo "Price Range: $Price";
echo "<br />Engine Size(s): $EngineSize[0]";
echo $EngineSize[1];
echo $EngineSize[2];
echo $EngineSize[3];
?>
</body>
</html>
Pages 96-97 - hidden2.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>hidden2.php</title>
</head>
<body>
<?php
$Hidden1 = $_GET['Hidden1'];
$Hidden2 = $_GET['Hidden2'];
$Hidden3 = $_GET['Hidden3'];
$ListBox = $_GET['ListBox'];
echo "The three options were:<br />";
echo "$Hidden1<br />";
echo "$Hidden2<br />";
echo "$Hidden3<br />";
echo "<br />You selected:<br />";
echo "$ListBox";
?>
</body>
</html>
Pages 101-102 - loan.php
Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>loan.php</title>
</head>
<body>
<b>Namllu Credit Bank Loan Application Form</b>
<br />
<br />
<?php
//make variables available from loan.html
$FirstName = $_POST["FirstName"];
$LastName = $_POST["LastName"];
$Age = $_POST["Age"];
$Address = $_POST["Address"];
$Salary = $_POST["Salary"];
$Loan = $_POST["Loan"];
//variables now available for use by loan.php
$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 loan application at this time");
?>
</body>
</html>
End Chapter 3 code examples.
If anyone found this to be an aide, post feedback and I will post the code examples as I work my way through the book.
Regards,
Steve