Jump to content


Photo

Can someone explain this to me about variables please


  • Please log in to reply
3 replies to this topic

#1 sdm

sdm
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 July 2006 - 01:07 PM

I have a site which I built sometime ago using PHP, it stopped working so I asked my host what the problem was.

This was their response:

"In this case we would like to let you know that several months ago the configuration on the servers was changed as php default setting was to have safe_mode enabled, it appears that your site has not registered the variables you are using so is conflicting with the safe_mode setting within php. It should also be noted that in future releases of php it is not possible to have it turned off.

It is pretty straight forward to register the variables in the script, best thing to do is just search in google.com ......"

I can't seem to find a good answer in Google, could someone help me out please.

Thanks,

SDM

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 08 July 2006 - 01:31 PM

I could be wrong, but im guessing that this is all to do with register_globals...

if you have a form with a text field such as:
<input type="text" name="firstname">

with register_globals on you could access the value from the field simply by using

$firstname - the firstname variable has automatically been created.

With register_globals off, you would have to use the $_POST array:

$firstname = $_POST[firstname;

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 July 2006 - 01:40 PM

Your host appears to be talking out of thier arse! AFAIK safe_mode doesnt affect variables at all. But what I think they was supposed to say was register globals rather than safe mode!

Register globals is the setting that affect variables the most. Now if they have disabled register_globals then any data you are retrieving from a form, or from the url, sessions or cookies will not work. As currently you are most probably doing something like this:
<?php
if($name)
{
   echo "Your name is $name";
}
?>
<form action="" method="post">
Name: <input type="text" name="name" value="Your name"><br />
<input type="submit" name="submit" value="Submit">
</form>
Which will work if register_globals is enabled. However when register_globals is disabled you'll need to use the superglobal arrays. The superglobal arrays are the following: $_POST, $_GET, $_COOKIE, $_SESSION etc,
So with the code above. Rather than using $name to get the users name when they submit the form you use $_POST['name'] instead. Or if use the GET method you use $_GET.

$_COOKIE and $_SESSION are straight forward as they hold the cookie and session data etc.

There a few more superglobal arrays however the five listed above are the most common.

#4 sdm

sdm
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 July 2006 - 02:50 PM

Thanks for your assistance, the site in question has been altered and is now working correctly.

SDM




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users