Jump to content

Is this PHP related?


3raser

Recommended Posts

All other pages on my browser (Google Chrome) work, but whenever I open up register.php, I get this:

 

Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.

 

My register.php code:

 

<?php

include_once('includes/config.php');
include_once('functions.php');

$return_content = AccountRelated(null, null, 3);

?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<title><?php echo $title; ?></title>
</head>
<body>

<div class="logo"><a href="index.php"><img src="style/images/logo.png"></a></div>

<center>

<div class="background">

<div class="container">
<?php echo $return_content; ?>
</div>

</div>
</center>

</body>
</html>

 

functions.php

 

<?php

function AccountRelated($username, $password, $query_type)
{

if($query_type == 1)
{
	$set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error());

	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = 'Sorry, no information was found';

	}
	else
	{
		$grab = mysql_fetch_assoc($set_query);

		//login information
		if($grab['COUNT(d.username)'] > 0)
		{
			$welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!";
		}
		else
		{	
			$welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!";
		}
	}
}
elseif($query_type == 2)
{
	$set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20");

	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = "Sorry, there are currently no files uploaded to view.";

	}
	else
	{
		while($row = mysql_fetch_assoc($set_query) == 0)
		{
			echo $row['title']."<br/>";
		}

	}	
}
elseif($query_type == 3)
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = md5($_POST['password']);

	if(!$username || !$password)
	{
		$return_content = "All fields are required! <table><form action='register.php' method='POST'>
		<tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr>
		<tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr>
		<tr><td><input type='submit' value='Register'></td></tr>
		</form></table>";

		AccountRelated($_POST['username'], $_POST['password'], 3);
	}
	else
	{
		$set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1");

		if(mysql_num_rows($set_query) == 0)
		{
			$return_content = "You have successfully registered the account ". $username ." with the
			password ". $password ."!";
		}
		else
		{
			$return_content = "An account with this username already exists.";
		}
	}
return $return_content;
}
else
{
	//nothing to process
}
}
?>

Link to comment
Share on other sites

Your AccountRelated() function calls itself (forever) and eventually produces a fatal runtime error and results in no output being sent to the browser, which is kind of what - ERR_EMPTY_RESPONSE suggests.

 

You should be developing and debugging your code on -

 

1) A system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, so that all the errors php detects will be reported and displayed, you will save a TON of time.

 

2) A local development system, so that you don't waste time constantly uploading your files to a server just to see the result of each change. You will save a TON of time.

Link to comment
Share on other sites

That function is considered "dangerous", as my host (000webhost) states:

 

PHP Errors: Warning: ini_set() has been disabled for security reasons

You can get this or any similar error by running a PHP script, because the desired function is considered to be dangerous, so it is disabled on main PHP configuration.

We have disabled most insecure PHP functions and are unable to allow them for any specific users due to potential security issues.

To remove this warning, edit your PHP script and remove the entire line where the disabled function is mentioned or insert this line on the top of PHP script:

error_reporting(0);

 

And I honestly don't see how it runs on forever. My other codes don't, and it should only echo out once as thats what the code is designed to do...

Link to comment
Share on other sites

See here:

	elseif($query_type == 3)
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = md5($_POST['password']);

	if(!$username || !$password)
	{
		$return_content = "All fields are required! <table><form action='register.php' method='POST'>
		<tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr>
		<tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr>
		<tr><td><input type='submit' value='Register'></td></tr>
		</form></table>";

		AccountRelated($_POST['username'], $_POST['password'], 3);
	}

 

Unless you submitted a form to this page, $_POST['username'] and $_POST['password'] will be blank. When PHP gets to this part, because they're blank, AccountRelated() gets called again, and once again $_POST['username'] and $_POST['password'] are empty, which leads to the same situation over and over again. Theoretically.

Link to comment
Share on other sites

Would exit() work?

 

Ok, tried exit() and register_shutdown_function('AccountRelated'); - But neither seemed to work.

 

And this is what it looked like:

 

<?php

function AccountRelated($username, $password, $query_type)
{

if($query_type == 1)
{
	$set_query = mysql_query("SELECT COUNT(d.username), u.date, u.username FROM uploads d, users u WHERE d.username = '$username' AND u.username = '$username' LIMIT 1") or die(mysql_error());

	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = 'Sorry, no information was found';

	}
	else
	{
		$grab = mysql_fetch_assoc($set_query);

		//login information
		if($grab['COUNT(d.username)'] > 0)
		{
			$welcome_return = "You have uploaded ". $grab['COUNT(d.username)'] ." files. You've registered on ". $grab['u.date'] ."!";
		}
		else
		{	
			$welcome_return = "You have uploaded 0 files. You've registered on ".$grab['date'] . "!";
		}
	}
}
elseif($query_type == 2)
{
	$set_query = mysql_query("SELECT title,views,downloads,description,username,date FROM uploads LIMIT 20");

	if(mysql_num_rows($set_query) == 0)
	{

		$content_return = "Sorry, there are currently no files uploaded to view.";

	}
	else
	{
		while($row = mysql_fetch_assoc($set_query) == 0)
		{
			echo $row['title']."<br/>";
		}

	}	
}
elseif($query_type == 3)
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = md5($_POST['password']);

	if(!$username || !$password)
	{
		$return_content = "All fields are required! <table><form action='register.php' method='POST'>
		<tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr>
		<tr><td>Password</td><td><input type='text' name='password' maxlength='30'</td></tr>
		<tr><td><input type='submit' value='Register'></td></tr>
		</form></table>";

		AccountRelated($_POST['username'], $_POST['password'], 3);
		register_shutdown_function('AccountRelated');
	}
	else
	{
		$set_query = mysql_query("SELECT username FROM users WHERE username = '$username' LIMIT 1");

		if(mysql_num_rows($set_query) == 0)
		{
			$return_content = "You have successfully registered the account ". $username ." with the
			password ". $password ."!";
		}
		else
		{
			$return_content = "An account with this username already exists.";
		}
	}
return $return_content;
}
else
{
	//nothing to process
}
}
?>

Link to comment
Share on other sites

Just delete those two lines

			AccountRelated($_POST['username'], $_POST['password'], 3);
		register_shutdown_function('AccountRelated');

and let the function return later down. Then that table with the signup form will be echoed later down. When you submit it, well, you'll have the username and password inside $_POST like you want.

 

Btw, it would be better to use more than just md5() to store a password (like salting it and running it through sha1() twice or something).

Link to comment
Share on other sites

Just delete those two lines

			AccountRelated($_POST['username'], $_POST['password'], 3);
		register_shutdown_function('AccountRelated');

and let the function return later down. Then that table with the signup form will be echoed later down. When you submit it, well, you'll have the username and password inside $_POST like you want.

 

Btw, it would be better to use more than just md5() to store a password (like salting it and running it through sha1() twice or something).

 

Thanks, it worked, and I will do!

Link to comment
Share on other sites

  • 1 year later...

Hi guys, I having the same problem also, and I'm using 000webhost also. Below is my code and I can actually insert the data into database but I wonder why the error message is keep showing and very annoying ....  :-\  Can anyone help me to identify the problem ?

 

<?php
for ($a = 1; $a <= $number ; $a++) {


	if ((${subject.$a}[1] == "Beta" ) || (${subject.$a}[1] == "beta" )){
	$two_hours_lec = (${subject.$a}[2])/2;
	$one_hour_lec = (${subject.$a}[2])%2;
	$beta_array_code = ${subject.$a}[0];
	$beta_lec = mysql_query("SELECT * FROM slot WHERE subject = '$beta_array_code' AND type = 'lecture' ");
		while ($beta_result = mysql_fetch_array($beta_lec)) {
				$beta_section = $beta_result[section];
					// for 2 hours class 
					$check_same_day = array(); // to empty the array
					for ($bs = 1 ;  $bs <= $two_hours_lec ; $bs ++ ){
					$check_hour2 = 100;  // to make sure after one loop, the content in while loop will be executed 
					$count_array = count($beta_slots); 
					$check_first_hour = array(0,0);
					$check_second_hour = array(0,0);
					// check whether the element in array[random number + 1] is continuous to the element in array[random number] with the while loop below
					while ((($check_hour2 - $check_hour1) != 1) || ($check_day1 != $check_day2)) {  
					$check_again = false;
					$rand = rand(0, $count_array -1);
					$rand2 = $rand +1; 
					$first_hour = $beta_slots[$rand];
					$second_hour = $beta_slots[$rand2];
					$check_first_hour = preg_split('#(?<=[a-z])(?=\d)#i', $first_hour); //split the alphabet and number into array where first element is alphabet and 2nd is number
					$check_second_hour = preg_split('#(?<=[a-z])(?=\d)#i', $second_hour);
					$check_hour1 = $check_first_hour[1];
					$check_hour2 = $check_second_hour[1];
					$check_day1 = $check_first_hour[0];					
					$check_day2 = $check_second_hour[0];
					$key = array_search($check_day1 , $check_same_day);
					if ($key !== false) {
					$check_hour2 = 100; // again to make sure the while loop will be executed
					} 
					$first_lec_hour = $check_hour1 * 100;
					$second_lec_hour = $check_hour2 * 100;
					}  
					array_push($check_same_day, $check_day1); // Insert the alphabet into the array to prevent the later hours of same section fall in same day
					$check_day = find_day($first_hour); // mon - fri
					$insert_first = mysql_query("INSERT INTO ".$beta_array_code." (section,type,day,start) VALUES ('$beta_section','lecture','$check_day','$first_lec_hour')");
					$insert_second = mysql_query("INSERT INTO ".$beta_array_code." (section,type,day,start) VALUES ('$beta_section','lecture','$check_day','$second_lec_hour')");
					if (isset($insert_first) &&  isset($insert_second)) {array_splice($beta_slots, $rand , 2);}

					}

					// if there is one hour class 
	 				if ($one_hour_lec  != "") { 
					while (!isset($insert_one)) { 
					$count_array1 = count($beta_slots);
					$rand1 = rand(0, $count_array1 -1);
					$one_hour = $beta_slots[$rand1];
					$check_one_hour = preg_split('#(?<=[a-z])(?=\d)#i', $one_hour);
					$one_hour_check = $check_one_hour[0];
					$key1 = array_search($one_hour_check , $check_same_day);
					if ($key1 !== false) { continue; }
					$check_day_1 = find_day($one_hour); 
					$one_lec_hour = $check_one_hour[1] *100;
					$insert_one = mysql_query("INSERT INTO ".$beta_array_code." (section,type,day,start) VALUES ('$beta_section','lecture','$check_day_1','$one_lec_hour')");
					}
					unset($insert_one);
					} 

		}
	}

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.