PHP register_globals =Off

  javaBalls 15:50 28 Dec 2005

This might be a long shot but I need help with dealing with data posted on my website using PHP.

When I post data from forms on my (localhost, home PC) everything works fine. However when I upload it to my hosting company it doesn't work at all.

I think that the problem is because my version of php has register_globals=On and my host has register_globals=Off.

By default PHP no longer has register_globals=On for security reasons. Here's the explanation

click here

Unfortunately I do not understand how I can convert to a new more secure version - perhaps using super globals??

Basically I post the variable from the form to another script that deals with it. At the top of the script I have something like this:

$message = $_POST['message'];

$_SESSION['error'] =
"You did not enter a message for your email.";
header("location: home_page.php?error_page=true");


But it does nothing!

Please help!

  Forum Editor 19:16 28 Dec 2005
  harristweed 18:19 29 Dec 2005

The code will redirect to the page called home_page.php if the posted message variable is empty.

It also sets the query string value pair error_page=true

If you want to display an error message you need something like....


if ($_GET[error_page]=="true");
echo $_SESSION[error];


The variable 'error_ page' is set to true, therefore you 'get it' from the query string and test it's contents. If the contents are equal to 'true' you echo out the session variable.

Also leave out the "'" in the variable names, they are not needed and give PHP more work to do.

i.e. $_GET[error_page]
NOT $_GET['error_page']

  javaBalls 18:42 29 Dec 2005

Forum Editor - Thanks. That link was useful. I suppose all the answers are in the php manual, it just depends on whether I understand the manual!

harristweed -

I know where I was going wrong.

It was to do with register_globals being set to Off on my host.

This meant that I had to initialise each session variable at the top of the page.

The header redirect worked but the error message did not appear.

Originally I had the following:


echo "<p class = 'error'><font size='+3'>!</font> $error</p>";

When I should have had:


$error = $_SESSION['error'];
echo "<p class = 'error'><font size='+3'>!</font> $error</p>";

Thanks for telling me about the quotes. I never knew this because php never complained about me using them. I will take them out from now on!


This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Best Black Friday Deals 2017

Black Friday Deals for Designers & Artists: Adobe, Apple, Corel Painter, Microsoft Surface, Wacom &e…

Best Black Friday Apple Deals 2017

Black Friday 2017 : date, sites participants & bonnes affaires