Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2004, 01:08 PM
Registered User
 
Join Date: Feb 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3 code available w/globals off

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
 
Old December 17th, 2004, 03:18 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, but can u explain why the codes in the book dont work? i didn't quite understand

 
Old December 19th, 2004, 09:57 PM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you! I've been struggling with this for a month. Keep posting please. I'm sure I'm not the only one trying to figure this out. Thanks again - You're my new best friend.
Tim

Quote:
quote:Originally posted by xtimox
 Thanks a lot, but can u explain why the codes in the book dont work? i didn't quite understand

 
Old January 10th, 2005, 12:22 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

basically, php5 has more security than php4, thus, the code in the beginning php4 book doesn't really work with php5. i ran into the same problem, but then i bought the beginning php5 book, which i highly recommend.
 
Old January 17th, 2005, 11:28 PM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you thank you thank you. the examples helped if only after the fact. it took me a week and a help from a friend of mine to get the idea that $var = $_POST["var"] is needed w/ the globals off. I only wish i'd seen your post much earlier.

I wonder, does anyone know whether there are plans to release an updated/new edition of beginning php4? i understand that php5 is the norm now however there are many of us out there who are working w/ php 4.3 and above who would like to have working code out of the book.

again, thanks for the code postings.


 
Old November 20th, 2006, 05:34 AM
Authorized User
 
Join Date: Nov 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot sambrose, your explanation help me to solve my problem... Maybe the authors of Beginning PHP4 should make changes to their books, buyers will not be satisfied in what they are buying if they dont explain clearly how their code are working in a certain setting... What if this p2p forum doesn't exist where those book buyers can get help... again thank you and hope someday i can return the favor...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Globals nabeelalkaff BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 29th, 2007 08:26 PM
$GLOBALS natmaster Beginning PHP 10 August 4th, 2004 03:00 PM
register globals problem nulogix Beginning PHP 4 June 16th, 2004 08:49 AM
Register Globals Off cmiller Beginning PHP 4 August 18th, 2003 05:21 PM
Code depending on Register Globals char Beginning PHP 2 July 31st, 2003 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.