PHP form

Discussion in 'Programming/Scripts' started by m u r, Jun 2, 2007.

  1. m u r

    m u r Member

    I tested this php form, and it worked on 2 out of three computers. The three computers were on different networks. The one that didn't work stalled after you hit submit . . . so you wouldn't get any of the error messages or anything. This happened whether it was on a PC or Mac, in Firefox, or IE. Any ideas what could be causing it? Thanks.

    Code:
    <?php
    $domainname = "mydomain.com";			/**  Change this to your own domain  	  **/
    $adminmail = "[email protected]";		/**  Change this to your own email address **/
    $webmail = "https://mydomain.com/mail/";	/**  Change this to your own webmail url  **/
    $scriptlocation = "/home/ecreate";	/**  Change this to point to your script  **/
    
    $name = escapeshellcmd($_REQUEST['name']);	
    $username = escapeshellarg(escapeshellcmd($_REQUEST['username']));
    $password = escapeshellarg(escapeshellcmd($_REQUEST['password']));
    
    if (!isset($_REQUEST['name'])) {
    ?>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <form method="post" action="index2.php">
      Full Name:
      <input type="text" name="name" />
      <br>
      Username:
      <input type="text" name="username" />
      <br>
      Password:
      <input type="password" name="password" />
      <input type="submit" />
    </form>
    </body>
    </html>
    <?php
    }
    
    elseif (empty($name) || empty($username) || empty($password)) {
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    You have left one of the information fields blank. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php
    }
    
    $reply = exec ("sudo $scriptlocation $name $username $password");
    
    switch ($reply) {
    case "success":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Success:<br>
    </div>
    Congratulations, <?php echo $name ?>, you have successfully created an email
    account at <?php echo $domainname ?> with username <?php echo $username ?>. You
    may access your webmail account from anywhere by going to <a href=<?php echo $webmail ?>><?php echo $webmail ?></a> and
    signing in.
    </body>
    </html>
    <?php;
    	$date = date('l dS \of F Y h:i A');
    	$subject = "Email User $name added to $domainname";
    	$body = "Email User was added on $date with a username of $username";
    	$headers = "From: root" . "\r\n" . "Reply-To: root@$domainname";
    	mail($adminmail,$subject,$body,$headers);
    	break;
    case "error2":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    You have used illegal characters in your first name. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php;
    	break;
    case "error3":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    You have used illegal characters in your last name. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php;
    	break;
    case "error4":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    You have used illegal characters in your username. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php;
    	break;
    case "error5":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    You have used illegal characters in your password. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php;
    	break;
    case "error7":
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    The username you have selected is already in use. Please press "back" on your
    browser and try again.
    </body>
    </html>
    <?php;
    	break;
    case ereg("^-bash: syntax error", $reply)
    	?>
    <html>
    <head></head>
    <body>
    <span style="color: rgb(204, 0, 0);">Error:<br>
    </div>
    Your input has caused an error. There might be a problem with your permissions.
    Please check your setup and try again.
    </body>
    </html>
    <?php;
    	break;
    }
    ?>
    
     
    Last edited: Jul 13, 2007
  2. falko

    falko Super Moderator Howtoforge Staff

    Are there any errors in Apache's error log?
     
  3. m u r

    m u r Member

    There were multiple instances of this in the error log:
    Code:
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try `grep --help' for more information.
    cut: write error: Broken pipe
    Usage:
    	htpasswd [-cmdpsD] passwordfile username
    	htpasswd -b[cmdpsD] passwordfile username password
    
    	htpasswd -n[mdps] username
    	htpasswd -nb[mdps] username password
     -c  Create a new file.
     -n  Don't update file; display results on stdout.
     -m  Force MD5 encryption of the password.
     -d  Force CRYPT encryption of the password (default).
     -p  Do not encrypt the password (plaintext).
     -s  Force SHA encryption of the password.
     -b  Use the password from the command line rather than prompting for it.
     -D  Delete the specified user.
    On Windows, NetWare and TPF systems the '-m' flag is used by default.
    On all other systems, the '-p' flag will probably not work.
    [Sun Jun 03 20:27:10 2007] [error] [client 71.199.15.128] File does not exist: /var/www/mydomain/favicon.ico
    Usage:
    	htpasswd [-cmdpsD] passwordfile username
    	htpasswd -b[cmdpsD] passwordfile username password
    
    	htpasswd -n[mdps] username
    	htpasswd -nb[mdps] username password
     -c  Create a new file.
     -n  Don't update file; display results on stdout.
     -m  Force MD5 encryption of the password.
     -d  Force CRYPT encryption of the password (default).
     -p  Do not encrypt the password (plaintext).
     -s  Force SHA encryption of the password.
     -b  Use the password from the command line rather than prompting for it.
     -D  Delete the specified user.
    On Windows, NetWare and TPF systems the '-m' flag is used by default.
    On all other systems, the '-p' flag will probably not work.
    [Sun Jun 03 20:27:16 2007] [error] [client 71.199.15.128] File does not exist: /var/www/mydomain/favicon.ico
     
  4. falko

    falko Super Moderator Howtoforge Staff

    These must come from some other script, as I don't see grep and htpasswd in the script you posted.
     
  5. Ben

    Ben Active Member Moderator

    Even if that might not solve the problem, for what is this ; in the script after <?php ?
    Normally you onle wirte <?php (or if short open tags enabled <? )
     

Share This Page