Warning: Cannot modify header information - headers already sent by (output started at /usr/local/apache1x/htdocs/phpESP/public/survey.php:62) in /usr/local/apache1x/htdocs/phpESP/public/handler.php on line 22 出现上面的错误。 setcookie("IP",$REMOTE_ADDR); 这就是 22 行。 为什么呢?
好的,马上贴出来。不过我觉得要是没有看过完成的 phpESP1.6.1 投票工具的话比较难看明白。<?php if (!defined('ESP_BASE'))
define('ESP_BASE', dirname(dirname(__FILE__)) .'/'); $CONFIG = ESP_BASE . 'admin/phpESP.ini.php';
if(!file_exists($CONFIG)) {
echo("<b>FATAL: Unable to open config file Aborting.</b>");
exit;
}
if(!extension_loaded('mysql')) {
echo('<b>FATAL: Mysql extension not loaded. Aborting.</b>');
exit;
}
require_once($CONFIG);
esp_init_db();
$_name = '';
$_title = '';
$_css = '';
if (isset($HTTP_GET_VARS['name'])) {
$_name = _addslashes($HTTP_GET_VARS['name']);
unset($HTTP_GET_VARS['name']);
$HTTP_SERVER_VARS['QUERY_STRING'] =
ereg_replace('(^|&)name=[^&]*&?', '', $HTTP_SERVER_VARS['QUERY_STRING']);
} if (!empty($_name)) {
$_sql = "SELECT id,title,theme FROM survey WHERE name = '$_name'";
if ($_result = mysql_query($_sql)) {
if (mysql_num_rows($_result) > 0)
list($sid, $_title, $_css) = mysql_fetch_row($_result);
mysql_free_result($_result);
}
unset($_sql);
unset($_result);
} // call the handler-prefix once $sid is set to handle
// authentication / authorization
include($ESPCONFIG['handler_prefix']); if (empty($_name) && isset($sid) && $sid) {
$_sql = "SELECT title,theme FROM survey WHERE id = '$sid'";
if ($_result = mysql_query($_sql)) {
if (mysql_num_rows($_result) > 0){
list($_title, $_css) = mysql_fetch_row($_result);
}
mysql_free_result($_result);
}
unset($_sql);
unset($_result);
}?>
<html>
<head><title><?php echo($_title); ?></title>
<?php
if (!empty($_css)) {
echo('<link rel="stylesheet" href="'. $GLOBALS['ESPCONFIG']['css_url'].$_css ."\" type=\"text/css\">\n");
}
unset($_css);
?>
</head>
<body>
<?php
unset($_name);
unset($_title);
include($ESPCONFIG['handler']);
?>
</body>
</html>
这个是 survey.php
return; define('ESP-HANDLER-PREFIX', true); if (!defined('ESP_BASE'))
define('ESP_BASE', dirname(dirname(__FILE__)) .'/'); require_once(ESP_BASE . '/admin/phpESP.ini.php');
require_once($ESPCONFIG['include_path']."/funcs".$ESPCONFIG['extension']); $GLOBALS['errmsg'] = ''; if(isset($HTTP_GET_VARS['sid'])) {
$GLOBALS['errmsg'] = mkerror(_('Error processing survey: Security violation.'));
return;
} if(isset($HTTP_GET_VARS['results']) || isset($HTTP_POST_VARS['results'])) {
$GLOBALS['errmsg'] = mkerror(_('Error processing survey: Security violation.'));
return;
} if (isset($sid) && !empty($sid))
$sid = intval($sid);
else if (isset($HTTP_POST_VARS['sid']) && !empty($HTTP_POST_VARS['sid']))
$sid = intval($HTTP_POST_VARS['sid']); if(!isset($sid) || empty($sid)) {
$GLOBALS['errmsg'] = mkerror(_('Error processing survey: Survey not specified.'));
return;
} if(empty($HTTP_POST_VARS['userid'])) {
if (!empty($HTTP_GET_VARS['userid'])) {
$HTTP_POST_VARS['userid'] = $HTTP_GET_VARS['userid'];
} elseif(!empty($HTTP_SERVER_VARS['REMOTE_USER'])) {
$HTTP_POST_VARS['userid'] = $HTTP_SERVER_VARS['REMOTE_USER'];
} elseif(!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$HTTP_POST_VARS['userid'] = urldecode($HTTP_SERVER_VARS['QUERY_STRING']);
} else {
$HTTP_POST_VARS['userid'] = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
} if(empty($HTTP_POST_VARS['referer']))
$HTTP_POST_VARS['referer'] = isset($HTTP_SERVER_VARS['HTTP_REFERER']) ?
$HTTP_SERVER_VARS['HTTP_REFERER'] : ''; if (empty($HTTP_POST_VARS['rid']))
$HTTP_POST_VARS['rid'] = '';
else
$HTTP_POST_VARS['rid'] = intval($HTTP_POST_VARS['rid']) ?
intval($HTTP_POST_VARS['rid']) : ''; if($ESPCONFIG['auth_response']) {
require_once($ESPCONFIG['include_path']."/lib/espauth".$ESPCONFIG['extension']);
$espuser = ''; $esppass = '';
if (isset($HTTP_SERVER_VARS['PHP_AUTH_USER']))
$espuser = $HTTP_SERVER_VARS['PHP_AUTH_USER'];
if (isset($HTTP_SERVER_VARS['PHP_AUTH_PW']))
$esppass = $HTTP_SERVER_VARS['PHP_AUTH_PW']; if(!survey_auth($sid, addslashes($espuser), addslashes($esppass)))
return; if (auth_get_option('resume')) {
$HTTP_POST_VARS['rid'] = auth_get_rid($sid, addslashes($espuser),
$HTTP_POST_VARS['rid']); if (!empty($HTTP_POST_VARS['rid']) && (empty($HTTP_POST_VARS['sec']) ||
intval($HTTP_POST_VARS['sec']) < 1))
{
$HTTP_POST_VARS['sec'] = response_select_max_sec($sid,
$HTTP_POST_VARS['rid']);
}
}
} if (empty($HTTP_POST_VARS['sec']))
$HTTP_POST_VARS['sec'] = 1;
else
$HTTP_POST_VARS['sec'] = (intval($HTTP_POST_VARS['sec']) > 0) ?
intval($HTTP_POST_VARS['sec']) : 1; define('ESP-AUTH-OK', true);?> 这个是handler-prefix.php
define('ESP_BASE', dirname(dirname(__FILE__)) .'/'); require_once(ESP_BASE . '/admin/phpESP.ini.php');
require_once($ESPCONFIG['include_path']."/funcs".$ESPCONFIG['extension']);
require_once($ESPCONFIG['handler_prefix']);
if(!defined('ESP-AUTH-OK')) {
if (!empty($GLOBALS['errmsg']))
echo($GLOBALS['errmsg']);
return;
}
esp_init_db(); if (empty($HTTP_POST_VARS['referer']))
$HTTP_POST_VARS['referer'] = ''; if(isset($results) && $results) {
survey_results($sid,$precision,$totals,$qid,$cids);
return;
} $sql = "SELECT status, name FROM survey WHERE id='${sid}'";
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0)
list ($status, $name) = mysql_fetch_row($result);
else
$status = 0; if($status & ( STATUS_DONE | STATUS_DELETED )) {
echo(mkerror(_('Error processing survey: Survey is not active.')));
return;
}
if(!($status & STATUS_ACTIVE)) {
if(!(isset($test) && $test && ($status & STATUS_TEST))) {
echo(mkerror(_('Error processing survey: Survey is not active.')));
return;
}
} if ($HTTP_POST_VARS['referer'] == $ESPCONFIG['autopub_url'])
$HTTP_POST_VARS['referer'] .= "?name=$name"; $num_sections = survey_num_sections($sid); $msg = ''; $action = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . $HTTP_SERVER_VARS['PHP_SELF'];
if (!empty($HTTP_SERVER_VARS['QUERY_STRING']))
$action .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; if(!empty($HTTP_POST_VARS['submit'])) {
$msg = response_check_required($sid,$HTTP_POST_VARS['sec']);
if(empty($msg)) {
if ($ESPCONFIG['auth_response'] && auth_get_option('resume'))
response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']);
$HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']);
response_commit($HTTP_POST_VARS['rid']);
response_send_email($sid,$HTTP_POST_VARS['rid']);
goto_thankyou($sid,$HTTP_POST_VARS['referer']);
return;
}
} if(!empty($HTTP_POST_VARS['resume']) && $ESPCONFIG['auth_response'] && auth_get_option('resume')) {
response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']);
$HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']);
if ($action == $ESPCONFIG['autopub_url'])
goto_saved("$action?name=$name");
else
goto_saved($action);
return;
} if(!empty($HTTP_POST_VARS['next'])) {
$msg = response_check_required($sid,$HTTP_POST_VARS['sec']);
if(empty($msg)) {
if ($ESPCONFIG['auth_response'] && auth_get_option('resume'))
response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']);
$HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']);
$HTTP_POST_VARS['sec']++;
}
}
if (!empty($HTTP_POST_VARS['prev']) && $ESPCONFIG['auth_response'] && auth_get_option('navigate')) {
if(empty($msg)) {
if (auth_get_option('resume'))
response_delete($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']);
$HTTP_POST_VARS['rid'] = response_insert($sid,$HTTP_POST_VARS['sec'],$HTTP_POST_VARS['rid']);
$HTTP_POST_VARS['sec']--;
}
}
if ($ESPCONFIG['auth_response'] && auth_get_option('resume'))
response_import_sec($sid, $HTTP_POST_VARS['rid'], $HTTP_POST_VARS['sec']);
?>
<script language="JavaScript">
<!-- // Begin <?php // This should really go into <head> tag ?>function other_check(name)
{
other = name.split("_");
var f = document.phpesp_response;
for (var i=0; i<=f.elements.length; i++) {
if (f.elements[i].value == "other_"+other[1]) {
f.elements[i].checked=true;
break;
}
}
}
// End -->
</script>
<form method="post" name="phpesp_response" action="<?php echo($action); ?>">
<input type="hidden" name="referer" value="<?php echo htmlspecialchars($HTTP_POST_VARS['referer']); ?>">
<input type="hidden" name="userid" value="<?php echo($HTTP_POST_VARS['userid']); ?>">
<input type="hidden" name="sid" value="<?php echo($sid); ?>">
<input type="hidden" name="rid" value="<?php echo($HTTP_POST_VARS['rid']); ?>">
<input type="hidden" name="sec" value="<?php echo($HTTP_POST_VARS['sec']); ?>">
<?php survey_render($sid,$HTTP_POST_VARS['sec'],$msg); ?>
<?php
if ($ESPCONFIG['auth_response']) {
if (auth_get_option('navigate') && $HTTP_POST_VARS['sec'] > 1) { ?>
<input type="submit" name="prev" value="Previous Page">
<?php
}
if (auth_get_option('resume')) { ?>
<input type="submit" name="resume" value="Save">
<?php
}
}
if($HTTP_POST_VARS['sec'] == $num_sections) { ?>
<input type="submit" name="submit" value="Submit Survey">
<?php } else { ?>
<input type="submit" name="next" value="Next Page">
<?php } ?>
</form>
这个是handler.php
这里就没有人能解决这个问题吗? 我是因为不会裁决的这样难 我知道IP和COOKIE的原理,但是不知道怎么加到程序里面,更可怕的是我不知道家在什么地方 能不能帮帮我呢? 今天就要交出来啦 谢谢大家帮帮忙吧
谢谢~~~ 我想在就是没有时间看明白这个程序中间的所有函数及处理方法。 这个功能又是很着急 您的意思是说将 COOKIE 设置在 handler.php 的最上面是吧。 我马上去添加一下试试看。
setcookie("IP",$REMOTE_ADDR);
这个是最简单的,这样就可以控制重复投票了
我在 handler.php 最上面添加了 require_once($ESPCONFIG['include_path']."/lib/cookie".$ESPCONFIG['extension']); 用来调用 COOKIE 处理模块。 $status = 0;
if (isset($cookie) $$ ($cookie == $sid)) $status = 1;
if (!isset($sign)) {
setcookie("cookie", $sid, time()+1200);
exit;
}
if (isset($cookie)) {
require "././index.php";
header("Location: $url_err");
} 这个是 COOKIE 处理模块 这样子写对吗?
哦? 可是还要控制在一段时间内只能投票一次,是不是因该增加 time()+60 控制在一分钟之内只能投票一次? 这样子是不是在一分钟之后同一个 IP 就能再次投票?
还有一个问题: 这个是控制 IP 重复投票,怎么才能控制一段时间里面 只能投票一次? 用不用重新建立一个 COOKIE 呢? 怎么写呢? 如果需要在当前页面弹出错误信息,应该怎么写? 谢谢~!!!
你的前面肯定已经有输出代码了
您的意思是说我应该将这个写在最前面? 我现在最大的问题是不知道应该将这个功能添加到什么地方。 您可以帮我看看应该添加到什么地方吗? 我现在只能很简单的设置 COOKIE 。 可是还是实现不了那两个功能。 您能帮我写一下吗? 我好学习一下,而且还能在很近的时间里面讲个两个功能添加上去。 谢谢~!!!