0

我有这段代码,但是当我登录 habbo 时,该功能不适用于在线图像,它只是离线显示图像:

<?php
$name = $_GET['habbo'];
$home = file_get_contents("http://www.habbo.com.br/home/".$name);
if (eregi("http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif", $home))
{
$img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif";
}
else
{
$img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif";
}
header("Content-type: image/gif");
$im = imagecreatefromgif($img);
imagegif($im);
imagedestroy($im);
?>
4

3 回答 3

1

问题是eregi从 PHP 5.3 到 5.4 已贬值,并在 PHP 5.5 中完全删除。但是就是说,查看您的代码是没有意义的,为什么eregi要从那里开始。看看这一行:

if (eregi("http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif", $home))

正在发生的模式匹配到底是什么?我觉得这==对我来说是一个简单的检查。所以我建议试试这个。我也在清理你的格式以提高可读性:

$name = $_GET['habbo'];

$home = file_get_contents("http://www.habbo.com.br/home/".$name);

$check = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif";

if ($check == $home) {
  $img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif";
}
else {
  $img = "http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif";
}

header("Content-type: image/gif");

$im = imagecreatefromgif($img);

imagegif($im);
imagedestroy($im);
于 2014-01-05T06:50:43.997 回答
0

尝试这个:

<?php
$name = $_GET['habbo'];
$home = file_get_contents('http://www.habbo.com.br/home/'.$habbo);
if (stristr($home, 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online_anim.gif') == TRUE)
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_online.gif';
}
    else
{
    $img = 'http://habboo-a.akamaihd.net/habboweb/63_1dc60c6d6ea6e089c6893ab4e0541ee0/2245/web-gallery/images/myhabbo/profile/habbo_offline.gif';
}
header('Content-type: image/gif');
$im = imagecreatefromgif($img);
imagegif($im);
imagedestroy($im);

当您不使用正则表达式时,stristr 的行为就像eregi ,它应该找到字符串并比较它是 TRUE 还是 FALSE。

更新: '=== TRUE' 到 '== TRUE'

于 2014-01-05T07:06:35.953 回答
0

有几件事:

首先,不推荐使用eregi以支持使用不区分大小写的正则表达式标记 (i)的preg_match 。因此,在需要进行正则表达式匹配的这种情况和未来情况下,您应该切换到使用 preg_match。

其次,eregi 和 preg_match 不返回布尔值。因此,您将需要使用身份运算符(=== 或 !==)来测试匹配。

最后,由于您没有在搜索中使用正则表达式,因此几乎不可能进行匹配。你需要做这样的事情:

if (eregi('/someregex/i', $home) !== FALSE){

查看 PCRE 样式正则表达式的语法(可在此处找到)以及检查您正在使用的函数的返回值可能会对您有所帮助。php.net 上有一条关于使用身份运算符检查返回的注释。

您似乎只是在搜索用户名,在这种情况下,通过stripos搜索可能更有意义,因为它比正则表达式快得多,并且仅搜索字符串文字,就像您正在做的那样:

$name = $_GET['habbo'];
$home = file_get_contents("http://www.habbo.com.br/home/" . $name);
if (stripos($home, "<whatever you're searching for>") !== FALSE) {

无论哪种方式,您都需要检查您实际搜索的内容。目前,您似乎正在 $home 的内容中搜索通向该图像的路径。除非存在完整的字符串,否则您将找不到它。如果你只是在 $home 中搜索 habbo_online_anim.gif,试试这个:

if (stripos($home, 'habbo_online_anim.gif') !== FALSE) {
于 2014-01-05T06:58:41.360 回答