【发布时间】:2012-07-30 02:49:27
【问题描述】:
我正在寻找我的代码中导致此 PHP 页面无法重定向的某种错误。我正在寻找是否有人可能知道此问题的原因(可能与 cookie 有关)。
inc_vars.php:
<?php
//some of the variables have been omitted.
$pid = 'gbb';
$dbtable ='';
$dbname = '';
$dbuser = '';
$dbpass = '';
$connect = mysql_connect('localhost', $dbuser, $dbpass);
if(!$connect){
header('Location: omitted');
die();
}
mysql_select_db ($dbname, $connect);
$webroot = 'omitted';
$share_page = $webroot . '/share-the-training';
$gift = $webroot . '/free-video?setuser=1199';
$bonus_content = $webroot . '/awesome-bonus';
$share_php = $webroot . '/share.php';
?>
刷新_id.php:
<?php
include_once('inc_vars.php');
$results = mysql_query("SELECT id FROM " . $dbtable . " WHERE email='" . $_GET['email'] . "'");
if(!$results || mysql_num_rows($results)==0){
header('Location: ' . $share_page . '?errorcode=1');
die();
}
$res_arr = mysql_fetch_assoc ($results);
setcookie($pid . "_viral", (string)$res_arr['id'], time() + 3600 * 365);
move_on();
function move_on(){
header ('Location: ' . $share_php);
die();
}
?>
当此人访问 refresh_id.php?email=their_email 时,他们应该重定向到 $share_php 页面。这不起作用。
但是,如果发生这种情况:refresh_id.php?email=an-email-that-is-not-in-database 然后脚本重定向到 $share_page 绝对没问题。
我已经尝试过使用和不使用 gbb_viral cookie。我不确定为什么这不起作用。如果您想自己寻找,所有页面现在都在互联网上。
省略
数据库中存在的一封电子邮件如下:acctrafficcop@gmail.com(对于那些想要测试的人)
更新
范围的愚蠢错误。我只是在 move_on() 函数中添加了全局 $share_php,现在一切正常。感谢大家对 SQL 注入的关注,我现在正在切换到准备好的语句。
【问题讨论】:
-
提防 SQL 注入攻击 - 您将 GET 变量直接转储到查询中。使用准备好的语句。