Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php.ini-dist 1

Status
Not open for further replies.

dingleberry

Programmer
Dec 13, 2002
143
US
Hey All, I recently installed php 4.3.0 on my bsd server running apache as a module. I think I have done something wrong because I have a form called search.html using fields named &quot;searchtype&quot; and &quot;searchterm&quot; being posted to this php file called results.php. Now I think .php files are being parsed because <? echo &quot;hello world&quot;; ?> works like a champ in printing hello world to my browser when I call it however I'm having a helluva time getting much further. basically just to test that my form names are being sent over I am using
<?
echo &quot;$searchtype&quot;;
echo &quot;$searchterm&quot;;
?>

in my results.php thinking it will display the contents of those variables but to no avail... I then tried declaring them like

$HTTP_POST_VARS[&quot;searchtype&quot;];
$HTTP_POST_VARS[&quot;searchterm&quot;];

before echoing them and still nothing. I'm stumped. I've even gone into my /usr/local/etc/php.ini-dist file and changed register_globals to On and then did a

/usr/local/sbin/apachectl restart

and still nothing. I'm really confused. Any ideas? For some reason, the form is not sending over the variables. attached is a copy of the .html file and the .php file. They are both in the same directory.

(search.html)


<html>
<head>
<title>Book-O-Rama Catalog Search</title>
</head>

<body>
<h1>Book-O-Rama Catalog Search</h1>

<form action=&quot;results.php&quot; method=&quot;post&quot;>
Choose Search Type:<br>
<select name=&quot;searchtype&quot;>
<option value=&quot;author&quot; selected>author</option>
<option value=&quot;title&quot;>title</option>
<option value=&quot;isbn&quot;>isbn</option>
</select>
<br>
Enter Search Term:<br>
<input type=&quot;text&quot; name=&quot;searchterm&quot; size=&quot;20&quot; maxlength=&quot;20&quot;>
<br>
<input type=submit value=&quot;Search&quot;>
</form>

</body>
</html>


and results.php

<?

$HTTP_POST_VARS[&quot;$searchterm&quot;];
$HTTP_POST_VARS[&quot;$searchtype&quot;];

echo &quot;$searchterm&quot;;
echo &quot;$searchtype&quot;;

?>


sorry about the 10 page post. I'm just a little baffled. Any help would be hugely appreciated. Also, does changing php.ini-dist change anything, or am I changing the wrong file alltogether.

-Dan
 
First of all, PHP doesn't read php.ini-dist. It reads php.ini. I recommend that you copy php.ini-dist to php.ini and implement your configuration edits there.

Do not declare variables in PHP. The only exception is arrays.

PHP 4.3.0 will not instantiate your form elements as individual variables, there is a configuration directive in php.ini called register_globals that controls this behavior. The default is off and I recommend you leave it this way.
4
But since you are using uninstantiated variables as array indeces, you're probably not going to get any data.

Since your version of PHP is 4.3.0, try changing results.php to read:

<?php
print_r ($_POST);
?>


And tell us what you get when you hit submit in your form. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks for the immediate response.

I did as you instructed and the following was displayed.

Array ( [searchtype] => title [searchterm] => Java )

In the real script I'm trying to learn, it must be implementing an older version of php or something. To test for existence of the individual form elements it uses a syntax like
<?php
trim $searchterm;
if (!$searchtype || !$searchterm)
{
echo &quot;did not enter a form field correctly, go back and try again&quot;;
exit;
}
.
.
.
?>
and that was what prompted me to try to test for the existence of the variable at all.

Is this the wrong syntax?
My php.ini file is in /home/temp/php-4.3.0/pear/tests/php.ini

and my php.ini-dist is in /usr/local/etc/php.ini-dist

just to be sure you want me to

cp /usr/local/etc/php.ini-dist /home/temp/php-4.3.0/pear/tests/php.ini

????

Thanks,
Dan
 
It's all a matter of the value of the configuration directive register_globals.

If register_globals is set to &quot;on&quot;, when you submit search.html to result.php, PHP will automagically create the variables $searchtype and $searchterm and populate them with the values you selected. The values will also be available as elements of the superglobal array $_POST (Use $_POST rather than $HTTP_POST_VARS. The former is &quot;superglobal&quot;, which means it is available everywhere, including user-defined functions. The latter is merely global.)

If register_globals is set to &quot;off&quot;, PHP will not instantiate the variables $searchtype and $searchterm. The values will only be available in $_POST.

The default setting for register_globals used to be &quot;on&quot;. In more recent versions of PHP, it's &quot;off&quot;. So older code often depends on the existence of form-field variables that PHP by default will not instantiate.


The PHP online manual recommends that you leave register_globals set to &quot;off&quot; because it closes a potential security hole. Read here for more information:
I recommend leaving it set to &quot;off&quot; because I agree with the manual about the security hole. Getting in the habit makes your code more maintainable (In six months you might not remember how the value got into $searchtype. You'll know immediately if you use $_POST['searchtype'].) and more portable (If you move your code to a new server, you can depend on $_POST['searchtype'] being there. Not so $searchtype.).


Performing trim on your variables is not necessary. Want the best answers? Ask the best questions: TANSTAAFL!
 
Although it may seem trivial to you it's those little humdingers that'll keep me scratching my head for hours on end. A thousand thanks to you for helping me out. Stupid SAMS php & mysql book didn't really mention anything about just putting

$searchtype = ($_POST['searchtype']);
$searchterm = ($_POST['searchterm']);

before ever using those variables in my php file. After I did that, it worked. Is there a ($_GET['variable']) that would apply to using method get?

Forgive my dumb questions I plead as I am very new to php, I've been dabbling in perl for much longer than this so the transition is sloooow.

Is it a good idea to overwrite my php.ini file in /home/temp/php-4.3.0/pear/tests/php.ini with the php.ini-dist file in /usr/local/etc/php.ini-dist?

I'm a little apprehensive to do this as
a.. that seems like an odd directory for php.ini to reside it although clearly it is there and outside of my ports directory it is the only location on my computer of this file and
b.. php.ini has like 2 lines of code in it where php.ini-dist has like 1000 so the files aren't similar.

Thanks,
Dan
 
For more information on $_POST, $_GET, $_COOKIE, and the other superglobal variables, read here:
Again, the book is assuming that register_globals is set to &quot;on&quot;. If that were the case, the two lines you mentioned:
$searchtype = ($_POST['searchtype']);
$searchterm = ($_POST['searchterm']);

would be unnecessary. PHP would have done that for you. But there is the security issue in the link I gave you earlier.

Canonically, at least on Linux, php.ini resides in /etc . And you will find that those extra lines in php.ini-dist are comments telling you about the configuration directives.

One thing to do: create the following script:
<?php
phpinfo();
?>
and point your web browser to it. Look for the following string: &quot;Configuration File (php.ini) Path&quot;. Put php.ini where PHP wants it, regardless of where it should be. Want the best answers? Ask the best questions: TANSTAAFL!
 
You could also use import_request_variables(string types [, string prefix]) to automatically import variables from POST, GET, or Cookie. Get more info at
I don't want to automatically import globals for &quot;GET&quot; & &quot;Cookie&quot;, but I do want to import &quot;POST&quot; globals. It works great.

-Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top