3raser Posted April 4, 2011 Share Posted April 4, 2011 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/ Share on other sites More sharing options...
dcro2 Posted April 4, 2011 Share Posted April 4, 2011 Try looking in your web server's error.log and open it in another browser to see if it's just Chrome. Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196904 Share on other sites More sharing options...
Jnerocorp Posted April 4, 2011 Share Posted April 4, 2011 it seems to be a problem with google chrome Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196906 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 Tried it in internet explorer, didn't work. My host, 000webhost, doesn't have an error log. Can anyone use the code on their site to check? Not sure why it's doing this. Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196931 Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2011 Share Posted April 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196944 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196959 Share on other sites More sharing options...
dcro2 Posted April 5, 2011 Share Posted April 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196962 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196975 Share on other sites More sharing options...
dcro2 Posted April 5, 2011 Share Posted April 5, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1196987 Share on other sites More sharing options...
3raser Posted April 5, 2011 Author Share Posted April 5, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1197009 Share on other sites More sharing options...
kcp88 Posted April 7, 2012 Share Posted April 7, 2012 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); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232706-is-this-php-related/#findComment-1335190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.