Page 1 of 1

Blank Page Problem

Posted: Sat Jun 02, 2007 3:01 pm
by m u r
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I tested this php form, and it worked on 2 out of three computers, all of which were on different networks. The one that didn't work stalled after I hit submit . . . all I got was a blank page . . .  no 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: Select all

<?php
$domainname = "mydomain.com";			/**  Change this to your own domain  	  **/
$adminmail = "info@mydomain.com";		/**  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;
}
?>
I am using it with the following script to create new users, though I don't think this is the problem:

Code: Select all

#!/bin/bash
emailgroupfolder=/home/emailgroup	## the folder in which you want new emailaccount homes to be created
emailgroupname=emailgroup		## the linux group to which your new email users will be assigned
useraddpath=/usr/sbin/useradd		## the path to the command useradd on your system (it's probably the same)

fname=$1
lname=$2
username=$3
password=$4
userlist=`cat /etc/passwd | cut -d: -f1 -s | grep $username`

enc_password=`/usr/bin/htpasswd2 -nb $username $password | cut -f2 -d :`

if [ $# -ne 4 ]; then
	echo "error6" ## There are more than or fewer than 4 arguments (Somebody has put down their middle name, or left off their last name)
	exit 1
fi
if [ "$username" = "$userlist" ] ; then 	## Username already exists on the system
	echo "error7" 
	exit 7;
fi
case "$fname" in
	*[!a-zA-Z0-9]*) echo "error2"; exit 2;; ## First Name contains illegal characters
	*);;
	esac
case "$lname" in
	*[!a-zA-Z0-9]*) echo "error3"; exit 3;; ## Last Name contains illegal characters
	*);;
	esac
case "$username" in
	*[!a-zA-Z0-9]*) echo "error4"; exit 4;; ## Username contains illegal characters
	*);;
	esac
case "$password" in
	*[!a-zA-Z0-9]*) echo "error5"; exit 5;; ## Password contains illegal characters
	*);;
	esac
/usr/sbin/useradd -m -c "$fname $lname" -d $emailgroupfolder/$username -p $enc_password -s '/bin/false' -g $emailgroupname -G 8 $username
echo "success"
exit 0
fi

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Jun 02, 2007 7:16 pm
by califdon
Although I don't immediately see a PHP syntax error in your script, it is normally a sign that there is a syntax error somewhere in your PHP code, if you get an absolutely blank screen. Look at the page source code in your browser and see what's there; it will probably be nothing but the HTML that wasn't included between <?php and ?> tags. What happens is that the web server tries to parse the PHP code but can't because there's a syntax error. I don't see why it would work on only some computers, though, that is quite strange.

Posted: Mon Jun 04, 2007 1:23 pm
by RobertGonzalez
You might also want to check the server error logs, as all errors that fire are typically sent to the server error logger.