Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 30th, 2003, 09:52 PM
Registered User
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code depending on Register Globals

Hello, I am complete newbie with NO PROGRAMMING EXPERIENCE and I have this book. I am wondering how much difficulty I am going to have trying to figure out which code was written prior to the register global settings default being turned off.

Are there specific chapters that I should be concerned with, is it just variable names? Are there things written in the book that I simply should not do and how will I know?

I guess that the bottom line is - should I go out and purchase a newly published book rather than spend my time using this one?

Thank you in advance for your advice.


Old July 31st, 2003, 01:43 AM
richard.york's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

Well you won't have any problems once you get a grasp on the concepts.

With PHP, each method is named, so once you get a handle on what's going on it'll be very easy to sort out which variables should be what.

The books don't do a very good job of explaining register globals. I personally had no idea that each variable has its own corresponding super-global array until I happened to subscribe to the PHP forums here on wrox.

You should get to know the super-global arrays and adapt whatever code you learn from a book to work with those instead of those that are created from register globals.

I don't think that you have to buy another book, necessarily, I have maybe six PHP books lying around and most of them haven't done anything for me. The big help for me was these forums and the PHP website... which is difficult to understand at first, as a newbie, because everything is written for the PHP savvy, not the begginer. But once you begin to understand how things work, becomes an invaluable tool. I think my most used book was the Beginning PHP book from wrox.

The super global arrays work like this:
$_POST - Is an array of variables containing data submitted via the post method of an HTTP request. Its set-up like this..

If you have an HTML form field declared like so;
<form method="post" action="my_script.php">
<input type="text" size="20" name="my_name" value="hello, world" />
You would probably see it referenced in your book like this;


echo $my_name;

This method relies on the register globals function...
The correct way, which does not rely on register globals is this:


echo $_POST["my_name"];

Which is a little easier to understand and when you get into more complicated scripts is also more secure and comes in very handy when dealing with functions and classes. And not to mention makes understanding the flow of your code much easier.

There are several of these super-global arrays, each having its own usefullness.

You may see for instance a reference to something like this in one of your book's examples...


global $PHP_SELF;


Which again has security issues... it should be referenced like this, no need for the global keyword!


echo $_SERVER["PHP_SELF"];


Well I'm sorry I can't get more deeply into the whole variable, super-global relationship...

Here is the most important URL you will ever need when dealing with PHP:

Here is the specific page on super-global variables:

My suggestion is read this page! And when you go to learning new concepts, reference this page to see if any of the variables that you are using could fit into one of these categories. Such as, variables that are written in all uppercase probably fit into the $_SERVER array, data submitted from forms fit into either the $_POST or $_GET array, depending on the method. URL query strings are the $_GET method. $_COOKIE, well its self-explanatory really. And finally $_SESSION is meant for data persistence... which is another subject all its own.

And if all else fails you've always got the PHP forums!

Good luck!
: )

Smiling Souls
Old July 31st, 2003, 11:45 AM
Registered User
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Wow, thank you Rich, you really cleared this issue up for me. I was worried that I would get completely confused trying to sort it out as I read the book, but I think it is fairly straight forward. I have read and printed out the super global variables page from php.net and I will keep it handy.

I'm off on a nine day cycling trip today and will be taking the extra weight of this book for some 'light reading material' ;)

Thank you very much for your reply.


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP register globals question Charagrin BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 February 6th, 2006 06:02 PM
Register Globals File Upload Problem fshequin Beginning PHP 0 April 24th, 2005 11:56 PM
register globals problem nulogix Beginning PHP 4 June 16th, 2004 08:49 AM
Error with variable..maybe register globals codefinder Beginning PHP 1 November 19th, 2003 03:31 PM
Register Globals Off cmiller Beginning PHP 4 August 18th, 2003 05:21 PM

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