PHP Register Globals Explained – Headers Already Sent – Undefined Variable

by on April 19th, 2008

There are some situations where simple code may work properly in case of PHP online or at localhost if register_globals are on. But not necessarily if register_globals are off.

Warning: Undefined Index – Use of Undefined constant selected
Warning: Header already sent

Sometimes messages like above that header already sent or undefined variable/ index can appear.


Make sure that there are no extra white spaces at the top of the PHP code.
OR else
You can use javascript redirect instead of header redirect.

Header Redirect
header("location: somepage.php?action=posted");

Use javascript redirection if header redirect is not working. i.e.

You can break php code before JS code and start again after it in PHP page. Hope you got the hint.

Use @ to avoid warnings


[email protected]$_REQUEST["name"];

Note how I have used @ which is not necessary to use but working at any strict server and with Globals off, to avoid warnings you can use this.

Register_Globals are by default off. These are for security reasons. Must be off. It is recommended to program with Globals off settings and use POST and REQUEST always while passing variables through pages. i.e.



echo $_POST["act"];
if(isset($_GET['action']) && $_GET['action']=="download")
// do download or something 

For more PHP scripts proceed to: [ PHP Magic Book ]