05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Security Redux<br />

Because security is such an important issue, we want to reiterate the main points of<br />

this chapter:<br />

• Check every value supplied to your program to ensure that the data you’re getting<br />

is the data you expected to get.<br />

• Always initialize your variables.<br />

• Set variables_order. Use $_REQUEST and friends.<br />

• Whenever you construct a filename from a user-supplied component, check the<br />

components with basename( ) and realpath( ).<br />

• Don’t create a file and then change its permissions.Instead, set umask( ) so that<br />

the file is created with the correct permissions.<br />

• Don’t use user-supplied data with eval( ), preg_replace( ) with the /e option, or<br />

any of the system commands (exec( ), system( ), popen( ), passthru( ), and the<br />

backtick (``) operator).<br />

• Store code libraries and data outside the document root.<br />

296 | Chapter 12: Security<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!