PHP configuration settings ?

I am learning PHP and I have a guy walking me through a simple project. the first thing he wanted me to do was write a very small script that would take a variable assignment from the URL address line.
Ex: If you type ...../index.php?a=abc

the script should respond by echoing abc.

The code:

<?php
if (isset($a))
echo $a;
else
echo 'Error, variable a not specified';
?>

While this works on his online server, it does NOT work on my server. It just flows down the the error text. If I add the following line to the top of the script,

$a = $_GET['a'];

It works.

He explained that it could be a setting in my PHP configuration for security reasons. I would like to change that, since this is not a production server . It's just one I tossed together to learn PHP on. While this may seem like a simple fix, what I am concerned about is OTHER possible issues that may not work the same on the two servers that will get me chasing my tail, thinking I've coded wrong.

Posted on Jul 26, 2006 7:45 AM

Reply
4 replies

Jul 26, 2006 8:00 AM in response to John-AVUSD

You're using the Apple-installed version of PHP, yes?

On OS X, you can find the PHP config file in /etc/php.ini. I can't remember if it's named something else by default, like "php.ini.default", or something like that. You'll need to edit it, change "register_globals" to true or ON, and then save the file as "php.ini" in your /etc directory. Then you'll need to restart Apache.

Just a note -- it is recommended to not turn on register globals as it is considered a pretty significant security risk. I know that you say it's not a production server, but it would be a shame to learn PHP using techniques that the PHP group themselves recommend avoiding.

If you can, I would recommend just translating the code to use the superglobals ($_POST, $_GET, $_REQUEST).

Jul 26, 2006 9:38 AM in response to Wesley Furgiuele

You know, I've been wondering about the security issue of that. What was to keep a hacker from seeing the script and figuring out what to add , after the ? and get where they want ?

It did frustrate me, though. I had no idea about the various settings in the PHP environment.

Oh, and by the way, Yes. It's the stock PHP that came with OS X ( 10.4 ) Server.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

PHP configuration settings ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.