Jump to content



Photo

Registering Globals

registering globals

  • Please log in to reply
5 replies to this topic

#1 I-WebDesign

I-WebDesign

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 2 August 2013 - 9:20 AM

Hi, I am a complete novice to PHP and have started to use this book but have been very frustrated by it so far. I am only at the second chapter, attempting to build and validate a simple form yet I cannot successfully see the results owing to constant 'undefined variables' etc.

 

According to the advice in the book these problems are caused by register globals being turned off and/or error reporting set too high, but I cannot do anything about either of these, so my question is... is this book realy of any use to me, and should it not have been written an a way which does not bring about these problems?

 

Is there any other way around this and is it worth persevering with the book in the hope that these problems will not continue or should I just give up?


  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4814 posts
  • LocationState College, PA (USA)

Posted 2 August 2013 - 11:22 AM

Hi. Sorry for your frustrations. A couple of things first:

 

- If you're a complete novice, the PHP & MySQL book may go at too fast of a pace for you. My "PHP for the Web" book goes at a slower pace.

- Are you really using the first edition of this book? That's the forum you posted in. The first edition is terribly outdated by now (this book is currently in its fourth edition). 


  • 0

#3 Antonio Conte

Antonio Conte

    Advanced Member

  • Members
  • PipPipPip
  • 1089 posts
  • LocationOslo, Norway

Posted 2 August 2013 - 10:04 PM

The first tip to give you is to download an IDE with PHP support. That will highlight errors in your script for you, provide auto completion of functions as you type, and other nice things.

 

A lot of them are free to. Check out one of the following:

- Eclipse

- Netbeans

 

to your problem. Undefined variable is not really a constant. That's an error message. It'll happen if you try to use a not previously declared variable in a structure which requires that. In simpler terms, if you feed a variable that does not exist to an if statement, a function or similar, you'll get that error message. I'll demonstrate it:

// Undeclared $iDoNotExistYet
if ( $iDoNotExistYet) {
   // You'll get an undeclared variable error.
}


//...Code below illustrates another script


// Here we declare a variable

$iDoExist = true;

if ( $iDoExist ) {
    // I exists/Is declared. This is true
}

Check out the code above. Your error is due to the problem illustrated in the first example, as explained.


  • 0

#4 I-WebDesign

I-WebDesign

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 5 August 2013 - 10:42 AM

Hi. Sorry for your frustrations. A couple of things first:

 

- If you're a complete novice, the PHP & MySQL book may go at too fast of a pace for you. My "PHP for the Web" book goes at a slower pace.

- Are you really using the first edition of this book? That's the forum you posted in. The first edition is terribly outdated by now (this book is currently in its fourth edition). 

Thanks for the reply Larry. It isn't that I'm struggling to understand the book, the problem appears to be the code which you have written.

 

As you state in your book, if Register Global is turned off or error reporting is set too high then this generates 'undefined variable' errors for the form which is designed in chapter two. I have seen that your code for these same pages written in the download files for later versions of this book is quite different, and therefore presumably does not generate these errors?

 

My problem is, as I cannot change the way PHP is configured on my server, these errors are generated each time and therefore I cannot tell if what I have written is really working. As this book progresses, will the style of code writing change to overcome these errors or are you saying that the book is now too old to be useful?

 

Regards

Patrick


  • 0

#5 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4814 posts
  • LocationState College, PA (USA)

Posted 5 August 2013 - 11:30 AM

You didn't clarify as to whether you're using the first edition or not, so I'll assume you are. The first edition is very, very outdated and I would not recommend that anyone use it anymore. Too much has changed since then. Yes, if you continue reading, you will learn what you need to do to prevent these errors, so that won't be a problem for long. But if you were to use a newer edition (there have been three since this edition), it'd be a much smoother process for you.

 

Right now, if you were to add this as the first line of PHP code:

extract($_REQUEST);

you shouldn't see those errors anymore (assuming the form was filled out). That's an easy fix, although not a secure one. Moreover...

 

A second issue is the first edition doesn't cover any changes in the technology that have occurred in the past decade. This includes new, helpful features. There have also been changes in general approaches and theories since then that would be reflected in newer editions. In short, you're setting yourself up for doing a lot more work to get through the book, only to end up knowing the standards and practices that were appropriate almost ten years ago.

 

If it's an issue of money, you could try buying a used copy of a later edition (even the third edition would be a significant improvement) or see if you can't get the latest edition from your local library.

 

All that being said, if you'd rather continue on with the first edition, I can still answer questions and help with whatever problems you encounter.


  • 0

#6 I-WebDesign

I-WebDesign

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 5 August 2013 - 4:04 PM

Okay thanks Larry and yes it is the first edition I am using, I bought this quite some time ago and didn't realise just how out of date it was. Guess I'll have to look at updating myself with something newer!

 

Thanks again

Patrick


  • 0