"The connection was reset" showing up on old code - php

I have a form with about 25 inputs and the code to process it. The last time the code was edited in any way was 3 weeks ago. I randomly started getting reset connection issues. To investigate, I began cutting out sections of the code to find the guilty sections (cut section, refresh, repeat). Once I narrowed it down to a particular section (one which when I cut it out, the error did not occur), I started to repeat the process with smaller sections of the culprit section. Finally, I had the entire section commented out. Still got the error. Then I deleted the commented out sections and no error!
This leads me to conclude that the error isn't in my code, but some recent change to the configuration of the server (I host with GoDaddy) or something like that. Any suggestions as to what could cause this error? I've never removed comments from code and fixed an error before.
Further information: The form loads correctly initially. Clicking any of the buttons gives me the error, however the code does completely precess before the error (I do some file in/output so I can see that it's working). This even happens with the "Clear All" button which skips the section I mentioned above, and simply reloads the form.
I am using no database interaction whatsoever. The script does utilize both Facebook and twitter APIs.
I really don't know how to proceed from this point. I'm willing to post the code from the entire file if necessary, but my investigation reveals that to be pointless. I can also provide a link to the offending page.
Update: I commented out all the code except the output of the HTML form itself. No processing code at all. Just one function to output the form. Clicking any button causes the connection reset. However if I delete this commented out code, I do NOT get the connection reset, the form just reloads.
Update #2. I uploaded the site to another host. The code runs fine with no issues.
Update #3. After an exhaustive examination, I've determined that the cause of the problem is the following function call:
preg_replace('/\b(\w)/e', 'strtoupper("$1")', $_POST['dessert_name'])
If I comment out this line, I get the connection reset error... If I delete it, the script runs perfectly.

You need to increase your php timeout limit in php.ini
This in my experience is almost always a timeout.
max_execution_time = 60
or at the top of your script add
set_time_limit(60);

Related

PHP Header Location does not works in some cases

I've a strange problem with PHP function header('location:anylink'); and is not a coding issue as the exact same script (is my script) works fine in other installations. Have checked it in at least 10 other websites from my clients, with different server configurations and works fine.
An example: I've in my code a check to see if the article id exists in database. If does not exists, it redirects to homepage. If exists, it shows the article page.
Some tests where the article id does not exists and (correctly) redirects to Blog homepage:
https://www.hostbignet.com/blog.php?do=article&id=400
https://oraclewebhost.org/blog.php?do=article&id=400
and here is the link in my site. As you can see it continue code execution and it shows the page, of course with empty data.
https://www.whmup.com/blog.php?do=article&id=400
Have tried at least a dozen of suggestions that I found here in similar issues but nothing changed. I used ob_start, I wrote Location instead location, I let space before URL, I added exit and exit() below redirection. Nothing solved the issue.
My code is (I tried even with adding the domain name before):
// Redirect Back
header('location:blog.php');
In addition. I even tried with window.location.href and window.location.replace Nothing again.
My server is CentOS 7 with CWP Pro.
Thank you
Chris
I was able to fix this issue by saving the file as ANSI. Whatever else encoding that I tried, does works.

PHP Page does not load data till I refresh after form submit

I have a main php Admin page that allows me to edit information contained within my database. I have several forms on the page, and a tabbed setup that allows me to nest the edit forms within each tab. All the forms refer Action="" back to the same php page for process and the page naturally looks to see if a button isset after POSTing otherwise just loads the usual tables and does not UPDATE the database.
Prior to web deployment I utilise XAMPP to develop the pages, however, once contented with the pages I upload to HostPapa. Whilst in the XAMPP environment, when i submit my information to be processed the page loads fine, the database is UPDATEd and the Success Message displays fine. However, once I upload to HostPapa and attempt the same steps, once i click the submit button and the data is sent back to the same page for processing, only a blank screen appears. When i hit refresh though it completes the processing and displays the Success Message. Data is UPDATEd in the database and nothing else appears to be wrong.
My questions are:
Any idea why my localhost website would display fine but my live version kind of stutters through the processing
Is this a setting on HostPapa that may need changing
Have i fallen pray to a coding taboo that prompts this response in the live environment
Worth noting that I had another XAMPP/HostPapa issue where I had not utilised the correct file name with Capitals in a form and this caused a failure as the file name did not match the coded file name exactly. This was rectified by insuring that file names and coded file name were match and case sensitive. The local XAMPP server did not care about case sensitivity which makes be believe that the form submission issue noted above may be a PHP option on HostPapa that is currently turn one.
Any assistance in this matter would be appreciated.
Regards,
C
To anyone who reads this and had a similar issue when utilising multiple forms on the same page. My issue is I had breaks(empty rows) between my <?php ?> tags in the header of the document.
I used several <?php ?> tags to encompass the different $_POST functions for my own clarity. This caused the server to interpret these breaks(empty rows) as an intentional space and made it appear that the header had already been sent. So naturally as my page attempted to load, the server believed i was attempting modify the header that had already been sent.
I believe this coding faux pas was masked by XAMPP during my offline build. I did a bit more research and I believe this also has something to do with the UTC selection.
At any rate, thank you Dony for attempting to assist. It was a hard issue to articulate.
Regards,
Cheyne

Website doesn't function the same way as it does on my localhost (wamp) server

First off, I ran into this issue when transferring all of my files from my localhost (wamp server) to my web server via FileZilla. Everything works great on my test server but when looking at it on my domain it doesn't appear the same nor does it function the same.
I tried to research this issue before asking and closest thing I found was this question here which doesn't help me with my specific problem.
What my test servers looks like and how the website should function on the web-server:
Show the sign-up and sign-in buttons on the navigation bar.
Show the proper content accordingly from the action page.
What my website is doing when uploading it to the web-server:
Shows the sign-up & sign-in buttons when navigating to the website (www.heartfx.org/test)
Does not display proper content like my localhost server does with the action page.
So instead of a user being linked to an external page for each function like login.php, register.php, forgot_password.php etc... they are linked to a single page like http://www.heartfx.org/action.php?action=register_account where I then $_get['action'] and display each "page".
The code on my web-server for some reason doesn't display those "pages" but only the navigation bar on top of the page and nothing under it.
How /action.php?action=sign_in should look(as it does on local server):
How /action.php?action=sign_in looks on the web-server:
Another thing to mention: I also have this question being posted / answered on, on another community where someone had me run the following line down the code until I ran into a spot where the line number didn't echo;
echo '<br>Line: ' .__LINE__; die;
The line number echo'd completely fine until I placed the line of code underneath a showHeader(''); function in my action.php page. When placing the line of code underneath a showHeader(''); function it did not echo the line number as it should with that statement.
We figured it was due to something with the showHeader(''); function which is being included in common.inc.php but cannot figure out what is wrong with the function that is causing it to not display each "page". The code on the web-server is exactly the same it is on the localhost server other then database credentials.
UPDATE: So after sitting idle at an action page (specifically I was at /action.php?action=register_account) for about 10 minutes and refreshing the page the module appeared as it should've when first loading the page. When roaming around the page for a bit and refreshing a 2nd time it AGAIN goes blank and run into the same issue.
Finally tracked down what was causing this issue and how to fix it. Inside of the showHeader('') that I am calling is another checkLogin() function that includes a Teamspeak3 query that displays my teamspeak server. That query for some reason was messing up the rest of my code (including the action.php page where I am trying to display everything.
Also would explain why very rarely I seen the page actually work and refreshing it, again made the page blank (other then the navigation bar) because the teamspeak query was still loading - causing the rest of the page not to load.
To fix this I simply removed the query from common.inc.php as it is not a mandatory function to have on my site. Thanks to everyone that helped me track down the issue.
/*
// Don't report any php errors.
error_reporting(0);
// load framework files
require_once("includes/libraries/TeamSpeak3/TeamSpeak3.php");
// connect to server, authenticate and spawn an object for the virtual server on port xxxx
$ts3_VirtualServer = TeamSpeak3::factory("serverquery://serverquerylogin:ATJ75oPF#63.251.20.99:14012/?server_port=14010&use_offline_as_virtual=1&no_query_clients=1");
// build and display HTML treeview using custom image paths (remote icons will be embedded using data URI sheme)
echo $ts3_VirtualServer->getViewer(new TeamSpeak3_Viewer_Html("includes/images/viewer/", "", "data:image"));
// Report all php errors again.
error_reporting(-1);
*/

PHP Redirect Not Working on Script Containing SQL Queries

Alright so I've been pouring over this code for 16+ hours and I cannot find where the issue is. Before you say anything- I know I'm prone to SQL injection and I need to setup more prepared statements; once I get the code working my next step is to work on those issues. I also know I need to add the TRUE and 303 parameter to the Header call- I'm just trying to get it running at this point.
The code worked beautifully until I began working on eliminating form submission on refresh and adding redirects at the end.
The page that is having the problem is called updateorder.php and here is a Pastie link for it: http://pastie.org/9188291
I created a page called Issue.php to funnel everyone off the page and to eliminate the possibility of any of the html code outputting. That did not help.
I removed the ?> PHP closing tag from the end since all the code is PHP and eliminate any white space possibility. That didn't help either.
The page before this has several submit buttons. This page looks at what button was pushed and runs the code when it meets the conditions of the IF.
When I submit the form using the DeleteThisOrder button, it operates perfectly.
When I submit the form using the PrintOnly button, it operates perfectly.
When I submit the form using the UpdateOnly button, but $ThisStatus <>1, it runs perfectly.
Here are the problems:
If I hit the UpdateOnly button and $ThisStatus does ==1, then it remains on this page (updateorder.php) and the screen is blank.
The exact thing happens if I use the UpdateCommit button.
Something is happening when it runs this particular section of the UpdateOnly script: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188298
And something happens when running this particular section of the UpdateCommit script: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188306
Whatever it is doing it is causing it not to redirect. The SQL code executes and does everything it is supposed to do in the database; it's updating the order, it's updating inventory- all of that executes fine- it's just not redirecting and it stalls somewhere in the script before it redirects and leaves me with a blank screen.
I've done the advanced search on the site and looked at every thing I could find using the keywords PHP, MySQL, Redirect, with no clue as to why it's not working. I've went over this code line by line to look for white space, tried using the whole website address for the redirect, added a space between the colon and the link in the header... I've tried a lot of things. I've even tried unhealthy things like banging my head on my desk, hitting my head with my palm, and pulling my hair... no results. I really appreciate your time.
Just in case- here is the code in my required db connection file: Sorry I don't have 10 reputation so it will not let me provide more links. Here is the Pastie number you can replace in the above Pastie link to see the code for this section: 9188351
By the way... as you can probably tell I'm still learning so it may not be 'beautiful code' yet but I'm working on getting there. Thanks again for your help.
When in development add error reporting to the top of your file(s)
error_reporting(E_ALL);
ini_set('display_errors', 1);
This will signal any errors if they are found in your code.
As per the error message from your comments:
To get rid of that Cannot modify header information - headers already sent... message, place
<?php session_start(); ?><?php // rest of your code... as your first lines of code while getting rid of the other one where it's at now, followed by the rest of your code. Make sure there is nothing above that, HTML etc. including any white spaces. If you still get that error message, make sure it's saved as UTF-8 without BOM. (Consult footnotes)
For the Notice: Undefined index: UpdateOnly error message, make sure your form element is named with no typos. I.e. name="UpdateOnly" --- UpdateOnly is not the same as updateonly PHP is case-sensitive.
As for your $result->free(); you mention you don't have that function, so just remove it.
Footnotes:
BOM (aka byte order mark)
For more information on this subject, visit: https://en.wikipedia.org/wiki/Byte_order_mark
For more information on error reporting, visit: http://php.net/manual/en/function.error-reporting.php

Data content not rendering on the webpage: Server not replying back

My page is made in php, I have qcodo which is layered on top of my database for the website.
Occasionally, the webpage does not render and instead of the content it should display it displays the website URL in the body. This problem started occurring after I added few fields in the database. At first I thought this might be a qcodo problem, so I tried qcube on a test page but the problem was not fixed.
Can anyone point me to right direction, I think it is the server that is not sending a sent content message to the client.
No errors? Try to turn on error and warnings.
If the error is not consistent then it could be your web/db server is busy.
Uhm, something very similar happened to me long time ago. It ended up it was due to an empty line that was somehow appended to one of my .php files.

Categories