Jony kale
Jony kale

Reputation: 85

PHP check if a value says true, if yes do this - doesn't work

I have a simple vote system that generates a shuffled code after you have voted. I have a little callback system that checks if the user voted on the site.

Looks like this:

http://gamingtoplist.net/?hasvoted=187&ip=82.81.33.168

187 = server ID on top list IP = The ip that has just voted.

If it says true when you go to this page, that means that IP has voted for that server ID. If it says false, that means the IP hasn't voted for the server ID.

I have just voted, as you see it says true.

Now to check if voted I do this:

if (isset($_POST['submit'])) {
    $check_GTL = file_get_contents("http://gamingtoplist.net/?hasvoted=187&ip=".$_SERVER['REMOTE_ADDR']);
        if ($check_GTL != "true") {
                $errors[] = "Sorry, but it seems like you haven't voted on all links, please contact Jony.";
        }

That line checks if you have voted:

$check_GTL = file_get_contents("http://gamingtoplist.net/?hasvoted=187&ip=".$_SERVER['REMOTE_ADDR']);

But for some random reason, the script tells me that check_GTL is not 'true'. Yet it is true....

What is wrong with it?

Thanks!

All of it:

if (isset($_POST['submit'])) {
    $check_GTL = file_get_contents("http://gamingtoplist.net/?hasvoted=187&ip=".$_SERVER['REMOTE_ADDR']);
        if ($check_GTL != "true") {
                $errors[] = "Sorry, but it seems like you haven't voted on all links, please contact Jony.";
        }


if($check_GTL == "true") { // if($votes > 0 && $check_GTL == "true") { disab led $votes cause runelocus didnt work lately for some reason.

        $insert = "INSERT INTO votes(auth, ip, received, time) VALUES('".$auth."', '".$_SERVER['REMOTE_ADDR']."', '0', '".time()."')";
        $insert = $connect->query($insert) or die(mysqli_error($connect));
        echo '<center><div class="movingerror" style="color: yellow">Thank you for voting! Your auth is <b>'.$auth.'</b>. Please type ::auth '.$auth.' to claim your reward</div></center>';


        $file = fopen("votes.txt", 'w');    
        fwrite($file, --$votes);
        fclose($file);
    }

} 

Upvotes: 0

Views: 107

Answers (1)

Alex Howansky
Alex Howansky

Reputation: 53636

Edit: Misunderstood the question, strike this.

file_get_contents() returns a boolean value not a string. There's a huge difference between:

if ($check_GTL == "true")

and:

if ($check_GTL == true)

You want the latter.

Upvotes: 1

Related Questions