POST/重定向引发“连接已重置"浏览器错误 [英] POST/Redirect throws a `Connection was reset` browser error

查看:69
本文介绍了POST/重定向引发“连接已重置"浏览器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的一位客户构建一个单页结账页面.此结帐应包含有关凭证、装运和付款的所有表格.也应该可以编辑以前输入的值.除了一件事外,一切都很好.

我的页面由多个包含构建而成:

  • 凭据
  • 发货
  • 付款

在每个包含中,我检查相关数据是否在会话中,如果是,我会显示不同的视图.这里没什么特别的.

例如:

如果已经设置了值,我还会显示一个编辑按钮.我这样做如下:

<h1 class="title-left">步骤 1 - 凭据</h1><div class="pull-left" style="width: 50%;">姓名:姓名<br/>地址:地址 11<br/>邮政编码:12345AA<br/>国家:国家<br/>

<br/><div style="clear: both;height: 10px;"></div><中心><form method="POST" action="/checkout/credentials/"><input type="hidden" name="edit" value="credentials"><button class="sexybutton Sexysimple Sexybestel">编辑</button></表单></中心>

关注:

<h1 class="title-left">第 2 步 - 发货</h1><i>选择发货方式</i><form method="POST" action="/checkout/payment/"><input type="radio" value="0" name="shipmentmethod">收集<br/><input type="radio" value="1" name="shipmentmethod">交付<br/><input type="submit" value="进入第三步" class="sexybutton Sexysimple Sexybestel pull-right" name="shipment"></表单>

在凭据中,我检查了 $_POST['edit'].如果已设置,我将再次显示该表单,其中包含客户先前在输入字段中填写的数据.

问题

每当我第一次单击编辑按钮时,它都会向我抛出一个Connection was reset 浏览器错误.如果我刷新页面,它会要求我再次提交表单.当我这样做时,错误消失了.我似乎无法弄清楚这是从哪里来的.我检查了服务器日志,但没有任何异常.

*注意:*同样的问题出现在发货和付款步骤之间.

相关的htaccess

选项 +FollowSymLinks重写引擎开启重写基数/命令允许,拒绝允许所有人RewriteCond %{HTTP_HOST} ^tapijttegelhandel.nl重写规则 ^(.*)$ http://www.tapijttegelhandel.nl/$1 [R=permanent,L]添加默认字符集 utf-8RewriteRule ^checkout//index.php?mod=checkout&action=show [NC,L,QSA]

index.php

case 'checkout':$action = isset($_GET['action']) ?$_GET['动作'] : '';开关($动作){案例已完成":# ...休息;案例取消":# ...休息;案例凭证":案例装运":案例付款":案例'编辑':默认:包括 $_SERVER['DOCUMENT_ROOT'].'checkout/show.php';休息;}休息;

进展

  • 我已经转储了会话变量以查看会话中是否有异常情况.(这里没什么奇怪的)
  • 我已经为 firefox 安装了 Tamper Data 插件来检查 POST 数据.(这里也没什么奇怪的)

更新

我在上次检查所有内容时跳过的代码中发现了一些内容.然而,这可能与我的问题有关.

<body onload="noBack();"onpageshow="if (event.persisted) noBack();"onunload="">

工作流程

/cart GET 200 OK/checkout/credentials/GET 304 OK/checkout/credentials/POST 304 OK# 编辑/checkout/credentials/POST - 错误连接已重置"# 刷新/checkout/credentials/POST 200 OK

解决方案

连接已重置"

有时可能意味着 php 崩溃.如果没有看到确切的文件,就很难猜测是否会发生这种情况以及为什么会发生这种情况.

一定要检查error_log,输入:php --info |grep 错误以查看它被记录到哪个文件(如果您使用的是 linux/unix).

我的猜测是流浪;某处的声明看到这个答案可能的原因:https://stackoverflow.com/a/20036720/988324

不过,您会在错误日志中找到一些痕迹.如果您能提供此信息,我可能会提供更多帮助.

I'm building a one-page checkout for a customer of ours. This checkout is supposed to contain all forms for credentials, shipment and payment. Editing previously entered values should also be possible. This is all going fine except for one thing.

My page is built of multiple includes:

  • credentials
  • shipment
  • payment

In each of these includes I check if the concerning data is in the session and if it is I show a different view. Nothing special here.

For example:

<?php
if (is_array($_SESSION['credentials'])) {
    ... show filled in values ...
} else {
    ... show form ...
}
?>

When values are already set, I also show an edit button. I do this as follows:

<div class="left-column">
    <h1 class="title-left">Step 1 - Credentials</h1>
    <div class="pull-left" style="width: 50%;">
        Name: name<br />
        Address: Address 11<br />
        Postal Code: 12345AA<br />
        Country: Country<br />
    </div>

    <br />
    <div style="clear: both;height: 10px;"></div>
    <center>
        <form method="POST" action="/checkout/credentials/">
            <input type="hidden" name="edit" value="credentials">
            <button class="sexybutton sexysimple sexybestel">Edit</button>
        </form>
    </center>
</div>

Followed by:

<div class="left-column">
    <h1 class="title-left">Step 2 - Shipment</h1>
    <i>Select a shipment method</i>
    <form method="POST" action="/checkout/payment/">
        <input type="radio" value="0" name="shipmentmethod"> Collect<br />
        <input type="radio" value="1" name="shipmentmethod"> Deliver<br />
       <input type="submit" value="Go to Step 3" class="sexybutton sexysimple sexybestel pull-right" name="shipment">
    </form>
</div>

In the credentials include I check for the $_POST['edit']. If it is set, i will show the form again with the customer's previously filled in data in the input fields.

The problem

Whenever I click the edit button the first time, it throws me a Connection was reset browser error. If I refresh the page, it will ask for me to submit the form again. When I do this the error is gone. I can't seem to figure out where this is coming from. I checked the server logs but there is nothing unusual there.

*Note: * The same problem occurs between the shipment and payment steps.

Relevant htaccess

Options       +FollowSymLinks
RewriteEngine On
RewriteBase /

order allow,deny
allow from all
RewriteCond %{HTTP_HOST} ^tapijttegelhandel.nl
RewriteRule ^(.*)$ http://www.tapijttegelhandel.nl/$1 [R=permanent,L]
AddDefaultCharset utf-8

RewriteRule ^checkout/               /index.php?mod=checkout&action=show [NC,L,QSA]

index.php

case 'checkout':
    $action = isset($_GET['action']) ? $_GET['action'] : '';
    switch ($action) {
        case 'completed':
            # ...
            break;

        case 'cancelled':
            # ...
            break;

        case 'credentials':
        case 'shipment':
        case 'payment':
        case 'edit':
        default:
            include $_SERVER['DOCUMENT_ROOT'].'checkout/show.php';
            break;
    }
    break;

Progress

  • I've dumped the session variable to see if there was something strange in the session. (Nothing strange here)
  • I've installed a Tamper Data plugin for firefox to check the POST data. (Nothing strange here either)

Update

I found something in my code I skipped when checking everything last time. This could however have something to do with my problem.

<script type="text/javascript">    
         window.history.forward();
         function noBack() { 
              window.history.forward(); 
         }
    </script>
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

Workflow

/cart GET 200 OK
/checkout/credentials/ GET 304 OK
/checkout/credentials/ POST 304 OK
# edit
/checkout/credentials/ POST - Error 'Connection was reset'
# Refresh
/checkout/credentials/ POST 200 OK

解决方案

"Connection was reset"

Can sometimes mean a php crash. Without seeing the exact files it's hard to guess if and why this is happening.

Make sure to check the error_log, type: php --info | grep error to see what file it's being logged to (if you are on linux/unix).

My guess is a stray break; statement somewhere see this answer for a possible cause: https://stackoverflow.com/a/20036720/988324

You would find some trace of this in your error logs though. If you can provide this I might be able to help more.

这篇关于POST/重定向引发“连接已重置"浏览器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆