...

View Full Version : strpos issue



thesavior
01-19-2007, 07:46 PM
Okay, this is my code:



if (strpos($ref, "image-space.net/competition.php")===true)
{
$db->query("UPDATE images SET votes=votes+1 WHERE id=".$id." AND parentid = ".$temp_catid." LIMIT 1") or badrequest($db->error());
}
else
{
badrequest("Hacking is bad...mmmkay. Referer was ".$ref);
}

The issue im having is that the if check is always returning false, so i get the "badrequest" error.

The referer it gives to me is ht*p://www.image-space.net/competition.php?catid=8 (without the * of course)

That means that
image-space.net/competition.php

is present, so it shouldn't be returning false. Any ideas?

GJay
01-19-2007, 08:02 PM
strpos returns the numeric position of the occurence, never 'true'. change your condition to "!==false"

thesavior
01-19-2007, 08:19 PM
Your partly right, a look back at the php manual showed me that it never returns true, but it does return false.

http://us3.php.net/strpos

I needed to change my code to this:


$ref = $_SERVER["HTTP_REFERER"];

$pos = strpos($ref, "image-space.net/competition.php");
if ($pos===false)
{
badrequest("Hacking is bad...mmmkay.");

}
else
{
$db->query("UPDATE images SET votes=votes+1 WHERE id=".$id." AND parentid = ".$temp_catid." LIMIT 1") or badrequest($db->error());
}

I just had to check for false not true.

Brandoe85
01-19-2007, 09:01 PM
He is all the way right, you did exactly as he stated, just flipped the statement from ! to ==.

thesavior
01-19-2007, 09:05 PM
hmm, I guess both of you are right. My bad. I understood his post wrong.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum