English 中文(简体)
防止在复读后重新提交表格,可修改标题信息
原标题:Trying to prevent form re-submission upon refresh, can t modify header information
  • 时间:2011-07-09 04:19:24
  •  标签:
  • php

我不想把同一形式的信息转过来。 然而,使用<代码>标题(地点:来宾书.php);给我一个错误:

警告:不能修改主人的信息——已经由(投稿开始在试验/编目中)寄出的头盔人员。 php on line 29

我不敢肯定,如果我把头盔放在适当的位置,我不十分熟悉使用:

<?php
$gb_str = "";   // $gb_str is the string we ll append entries to
$pgeTitle = "View and Sign Guestbook";

// If form is submitted, then insert into DB
if (!empty($HTTP_POST_VARS["submit"])) {
    // initiate some vars
    $dbHost = ;
    $dbUser = ;
    $dbPass = ;
    $dbDatabase = ;
    $li = mysql_connect($dbHost, $dbUser, $dbPass) or die("Could not connect");
    mysql_select_db($dbDatabase, $li) or die ("could not select DB"); 

    $name = mysql_real_escape_string($HTTP_POST_VARS["name"]);
    $email = mysql_real_escape_string($HTTP_POST_VARS["email"]);
    $comment = mysql_real_escape_string($HTTP_POST_VARS["comment"]);
    $date = Date("Y-m-d h:i:s");

    $gb_query =     "insert into entries
            values(0,  $name ,  $email ,  $comment ,  $date )";

    mysql_query($gb_query);
    $res = mysql_affected_rows();

    // See if insert was successful or not
    if($res > 0) {
    $ret_str="Your guestbook entry was successfully added!";
    header( Location: guestbook.php );
    exit(); // End the request

    } else {
        $ret_str = "There was a problem with your guestbook entry. Please try again.";
    }

    // Append success/failure message
    $gb_str .= "<span class="ret">$ret_str</span><BR>";
    mysql_close();
}
?>
最佳回答

You have BOM or just regular spaces in the beginning of the file. Just remove them

问题回答

Most probably you have sent output before setting header();.
Try disabling notices (and probably warnings) and make sure you don t send any output before setting header();.

<?php
error_reporting(E_ALL ^ E_NOTICE); // Print all errors except notices - they come out for example when you re requiring an undefined var.
$gb_str = "";   // $gb_str is the string we ll append entries to
$pgeTitle = "View and Sign Guestbook";

// If form is submitted, then insert into DB
if (!empty($HTTP_POST_VARS["submit"])) {
    // initiate some vars
    $dbHost = "localhost";
    $dbUser = "someuser"; 
    $dbPass = "password";
    $dbDatabase = "database";
    $li = mysql_connect($dbHost, $dbUser, $dbPass) or die("Could not connect");
    mysql_select_db($dbDatabase, $li) or die ("could not select DB"); 

    $name = mysql_real_escape_string($HTTP_POST_VARS["name"]);
    $email = mysql_real_escape_string($HTTP_POST_VARS["email"]);
    $comment = mysql_real_escape_string($HTTP_POST_VARS["comment"]);
    $date = Date("Y-m-d h:i:s");

    $gb_query = "insert into entries values(0,  $name ,  $email ,  $comment ,  $date )";

    mysql_query($gb_query);
    $res = mysql_affected_rows();

    // See if insert was successful or not
    if($res > 0) {
        $ret_str="Your guestbook entry was successfully added!";
        header( Location: guestbook.php );
        exit(); // End the request

    } else {
        $ret_str = "There was a problem with your guestbook entry. Please try again.";
    }

    // Append success/failure message
    $gb_str .= "<span class="ret">$ret_str</span><BR>";
    mysql_close();
}
?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签