PHP register_globals =Off

  javaBalls 15:50 28 Dec 05
Locked

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'];


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

}


But it does nothing!

Please help!

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

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

<?php
session_start();

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 05

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:

CODE

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

When I should have had:


CODE

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

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!

Thanks.

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

Best phone camera 2016/2017: Galaxy S7 vs iPhone 7 vs Google Pixel vs HTC 10 Evo vs OnePlus 3T vs…

1995-2015: How technology has changed the world in 20 years

Best Christmas Agency Projects of 2016

Super Mario Run preview | Hands-on first impressions of Super Mario Run: Mario's iPhone & iPad…