从cookie

时间:2017-12-12 15:49:21

标签: php arrays cookies

好吧,我有一个相当奇怪的问题,我已经坐了一段时间没有成功。我的页面结构大致如下:

<?php
ob_start();
error_reporting(E_ALL);

然后我创建一个包含用户信息的数组:

$USER = array('ID' => md5(uniqid(rand(),1)),
          'referrer' => $_SERVER['HTTP_REFERER'],
          etc.
       );

这将有10个条目左右。 然后我检查用户是否已经设置了我的cookie,如果他们没有,我做(在输出任何内容之前,即在<html>标记之前):

$data = base64_encode(serialize($USER));
setcookie('cookiename', $data, time()+86400*30, '/','mydomain.com',1,1);

到目前为止一切顺利。现在说用户然后导航到我网站上的另一个页面。现在已经设置了cookie,所以如果检查返回true,我会用以下内容读取cookie:

$DUMMY = unserialize(base64_decode($_COOKIE['cookiename']));

所以现在$ DUMMY应该具有先前写入cookie的相同数组结构。真正令人困惑的是,当我尝试访问时:

$uid = $DUMMY['ID'];

我在error_log中收到警告说:

PHP Notice:  Undefined index: ID

这真的很奇怪,因为(1)它只会在cookie存在的情况下读取cookie,如果它存在,它应该有&#39; ID&#39;首先写入它的元素(我确实用print_r($DUMMY);进行了双重和三重检查,并且所有元素都在那里)。此外,当我尝试使用$uid 我可以时,也就是说,它确实具有它应该具有的值。所以一切似乎都没问题,除了我的error_log文件获得1000条这些PHP警告消息。有什么想法吗?

我在页面页脚的最末端执行ob_end_flush();。 感谢。

P.S。:正在发生一些更奇怪的事情。 好的测试目的,我添加了一些IP过滤器,所以只有当我访问页面时才加载cookie脚本。它似乎有效,因为数据库中没有进一步的条目。尽管如此,错误消息仍然在error_log文件中消失。我正在提供摘录:

[13-Dec-2017 01:04:34 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:04:35 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:05:06 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:05:07 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:05:38 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:05:39 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:06:10 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:06:11 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:06:42 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:06:43 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:07:14 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:07:15 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:07:46 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:07:47 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:08:18 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:08:20 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:08:50 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:08:51 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:09:22 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:09:23 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:09:54 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:09:55 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:10:26 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:10:27 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:10:58 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:10:59 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:11:30 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:11:31 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:12:03 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:12:03 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:12:35 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:12:35 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:13:07 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:13:07 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:13:39 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:13:39 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:14:11 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:14:11 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:14:43 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:14:43 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:15:15 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:15:15 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:15:47 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:15:47 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:16:19 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:16:19 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:16:51 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:16:51 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:17:23 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:17:23 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:17:55 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:17:55 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:18:27 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51
[13-Dec-2017 01:18:27 Europe/Berlin] PHP Notice:  Undefined index: ID in /home/xxxxxxxx/public_html/include/usertrack.inc.php on line 51

有两件事让我觉得奇怪: 1)为什么我首先看到它们,因为脚本仅包含在我的IP中,并且 2)这些消息有一些奇怪的规律性。每30秒约2次点击。

这是什么?某种黑客攻击?但即使是一些奇怪的DDoS,为什么攻击者会看到cookie脚本呢?我的IP过滤器是:

if ($_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx') { // the x's would be my IP
    require 'include/usertrack.inc.php';
    flush();
}

这对我来说是绝对的谜。

1 个答案:

答案 0 :(得分:0)

噢,伙计......我心疼。我刚刚解决了

好的,我最近对目录结构进行了一些更改,我正在运行自己的云服务器(使用owncloud)。由于目录结构的变化,owncloud不再找到它应该与之同步的目录。所以基本上,它每30秒就试图联系服务器以找到目录。由于它来自我的机器,owncloud请求确实有我的IP号码所以通过IP过滤器,但由于它无法找到目录,它必须触发一些404或其他东西。

我不确定owncloud会发出什么样的请求,但它必须触发了cookie脚本,甚至可能接受了cookie但可能不允许我的脚本读取cookie或者在设置的时候删除它。无论哪种方式,现在我再次将owncloud指向正确的目录,错误消息就会停止显示,并且error_log是干净的。

男人...我生命中的两天我永远不会回来!

对此感到抱歉。