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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Is it running? How do I know? 1

Status
Not open for further replies.

josel

Programmer
Oct 16, 2001
716
US
I have installed PHP and Apache on my WINXP notebook. I configured apache to load PHP as module.

I installed Dev-PHP IDE to write PHP code. I wrote a simple PHP/HTML page as per a book I am reading, nothing works.

OK, I've seen many cases where code printed on books do not work - I've spend a number of hours playing with this "very" simple, but it is kicking my behind, program and I cannot get it to work.

Now the questions:
Q. How do I make sure PHP engine is running?
Q. What is wrong with this code?
Code:
<html>
<head>
 <title>Contact Info Checker</title>
</head>
<body bgcolor="#FFFFFF">
<?PHP
 /* Declare some functions */
 function print_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os)
 {
?>
<form action="/form_checker.php" method="post">
 <table cellspacing="2" cellpadding="2" border="1">
 <tr>
  <td>First Name</td>
  <td><input type="text" name="ff_fname" value="<?php print($ff_fname); ?>"></td>
 </tr>
 <tr>
  <td>Last Name<b>*</b></td>
  <td><input type="text" name="ff_lname" value="<?php print($ff_lname); ?>"></td>
 </tr>
 <tr>
  <td>eMail Address<b>*</b></td>
  <td><input type="text" name="ff_email" value="<?php print($ff_email); ?>"></td>
 </tr>
 <tr>
  <td>Zip Code<b>*</b></td>
  <td><input type="text" name="ff_zip" value="<?php print($ff_zip); ?>"></td>
 </tr>
 <tr>
  <td>Operating System</td>
  <td><input type="text" name="ff_os" value="<?php print($ff_os); ?>"></td>
 </tr>
 </table>	
 <input type="submit" name="ff_submit" value="Submit!">
 <input type="reset">
</form>
<?PHP
}   /* EOF - PrintForm() */

function check_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os) 
{
 if(!isset($_POST['ff_lname']) || !isset($_POST['ff_email']) || !isset($_POST['ff_zip'])):
  print("<h3>You are missing some required fields!</h3>");
  if(!isset($_POST['ff_lname'])) 
  {
   print("You need to fill in your <b>Last Name</b>.<br>");
  }
  if(!isset($_POST['ff_email']) || $ff_email == "")
  {
   print("You need to fill in your <b>eMail Address</b>.<br>");
  }
  if(!isset($_POST['ff_zip']))
  {
   print("You need to fill in your <b>Zip Code</b>.<br>");
  }
  print_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os);
  else:
   confirm_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os);
 endif;
}  /* EOF check_form() */

function confirm_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os)
{
?>
<h2>Thanks! Below is the information you sent us.</h2>
<p><b>Contact Info</b>
<?PHP
print '<br>$ff_fname $ff_lname<br>$ff_email<br>Zip: $ff_zip<br>OS: $ff_os\n';
}
/* Begin Main Program */
if(!isset($_POST['ff_submit'])):
 ?>
 <h3>Please enter your information</h3>
 Fields with a "<b>*</b>" are required.<p>
 <?PHP
 print_form("","","","","");
else:
 check_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os);
endif;
?>
</body>
</html>

As you can see, it just does not get simpler than this (I can do this in my sleep in ColdFusion). Three very basic steps:
1. Get input
2. Validate input
3. Show input on screen

I think that the problem is with PHP Engine not running or not properly configured (I rather admit to that than being beaten by the above posted code).

Your help will be greatly appreciated.

Regards,


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
unless you have register_globals() switched on then this line

Code:
 check_form($ff_fname, $ff_lname, $ff_email, $ff_zip, $ff_os);

should be

Code:
check_form($_POST['ff_fname'], $_POST['ff_lname'], $_POST['ff_email'], $_POST['ff_zip'], $_POST['ff_os']);

to test php installation just create a text file with the following in it
Code:
<?php phpinfo(); ?>
and save it to your webroot with a php extension.
 
jpadie,

Changing code as suggested produced the expected results.

Now, I wonder if setting register_global() ON is or not a security problem or poor practice.

Thank you so much for this very valuable tip!

You would think that the book would tell you "Oh, make sure you have these settings .... so that the code in the book works". In the other hand, these little mountains are mostly the reason why "Teach Yourself Books" kind 'da teach you a thing or two.


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
perceived (and received) wisdom is that register globals is a "bad thing". php 5 has RG turned off by default and php 6 does not, i believe, had RG at all.

 
I looked this up within php.ini and this is what I found

Code:
; Whether or not to register the EGPCS variables as global
; variables.  You may want to turn this off if you don't
; want to clutter your scripts' global scope
; with user data.  This makes most sense when coupled with 
; track_vars - in which case you can access all of the GPC 
; variables through the $HTTP_*_VARS[], variables.
;
; You should do your best to write your scripts so that 
; they do not require register_globals to be on
; Using form variables as globals can easily lead
; to possible security problems, if the code is not very 
; well thought of.
register_globals = Off

Having read that, I guess that it is staying OFF.

Regards,


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top