Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: strpos issue

  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    strpos issue

    Okay, this is my code:

    PHP 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?

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    strpos returns the numeric position of the occurence, never 'true'. change your condition to "!==false"
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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:

    PHP Code:
    $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.

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    He is all the way right, you did exactly as he stated, just flipped the statement from ! to ==.

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    hmm, I guess both of you are right. My bad. I understood his post wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •