Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 30th, 2003, 09:52 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
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.

Charla

Reply With Quote
  #2 (permalink)  
Old July 31st, 2003, 01:43 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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;
<?php

#my_script.php

echo $my_name;

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

<?php
#my_script.php

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...

<?php

global $PHP_SELF;

?>

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

<?php

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:
http://www.php.net/manual/en/index.php

Here is the specific page on super-global variables:
http://www.php.net/manual/en/languag...predefined.php

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!
: )
Rich




:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote
  #3 (permalink)  
Old July 31st, 2003, 11:45 AM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Charla

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:41 AM.


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