can u see the problem?

Discussion in 'PHP' started by cavendano, Nov 8, 2007.

  1. #1
    
    $uname = $_POST["name"];
    $data = file_get_contents("http://$uname.stumbleupon.com/favorites/");
    $msite = $_POST['msite'];
    $regex = '/$msite/';
    
    if (preg_match($regex, $data, $match)){	
    echo "You Stumbled Successfully!";
    }
    else{
    echo "Try Again!";
    
    PHP:
    What is happening is that the outcome is always successful even though it is a false statement.
     
    cavendano, Nov 8, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $regex = '/$msite/';
    
    PHP:
    $msite won't be parsed between single quotes. Use double quotes instead.
     
    nico_swd, Nov 8, 2007 IP
  3. Demonic

    Demonic Active Member

    Messages:
    821
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Change:
    $regex = '/$msite/';
    Code (markup):
    to:
    $regex = "/$msite/i";
    Code (markup):
     
    Demonic, Nov 8, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Actually, since you're using user input in the expression, you might as well want to use preg_quote() to avoid errors.
     
    nico_swd, Nov 8, 2007 IP
  5. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #5
    I tried your advice with a session register but the script keeps on randomizing the output....

    for example if I echo one of the session variables and then hit submit it tries to verify it against a different random variable...meaning sometimes it will fail and at times it will succeed.
     
    cavendano, Nov 12, 2007 IP