Jump to content

[SOLVED] huuuh? undefined session??


kellz

Recommended Posts

I was attempting (AGAIN) to make 1 of those things that stops bots and I think apart from it not working it's a little better lol , well, it half works^^

 

<?php
session_start();
?>

<?php

if (isset($_SESSION['correct'])) $correct = $_SESSION['correct'];

if (isset($_POST[$correct])) {
echo 'you were right!';
} else {
    echo '...might you be a bot?';
}

if ($directory = opendir('pics')) {
    while(($filename = readdir($directory)) !== false) {
    if (stristr($filename, ".gif")) {
	    $f_arr[] = $filename;
	}
    }
    closedir($directory);
}

shuffle($f_arr);

$_SESSION['correct'] = substr($f_arr[0], 0, strpos($f_arr[0],'.'));
echo '<img src="pics/'.$f_arr[0].'" width="32" height="32" /><br>';
shuffle($f_arr);
echo '<form id="form1" name="form1" method="post" action="">';

foreach ($f_arr as $img) {
    echo '<label>'.substr($img, 0, strpos($img,'.')).
'</label><input name="'.substr($img, 0, strpos($img,'.')).'" type="radio"    value="radiobutton" />';
}

echo '<input type="submit" name="Submit" value="Submit" /></form>';

?>

 

it keeps saying "...might you be a bot?" before the form is even submit! is it true that PHP can become posessed? so yea.. I run out of idea's, as far as I can see it should be right!  :'( I spend all day reading and it only gets me more problems!!

 

ps: please Please PLEASE dont write a new 1 or edit it all to much, I hate getting everything solved for me.. just a little bit is ok to show me where i went wrong.. thanks you!

Link to comment
Share on other sites

I don't see where you are even checking Submit:

 

if (isset($_SESSION['correct'])) $correct = $_SESSION['correct'];

 

if (isset($_POST[$correct])) {

echo 'you were right!';

} else {

    echo '...might you be a bot?';

}

 

The first if isset is probably false, so it goes to the second if isset which is false so it echo's Might you be a bot?

 

You need code to check if Submit is set.

Link to comment
Share on other sites

i thought so too and before i posted i tried this:

 

if (isset($_POST['Submit']) && isset($_SESSION['correct'])) $correct = $_SESSION['correct'];

    if (isset($_POST[$correct])) {
    echo 'you were right!';
    } else {
        echo '...might you be a bot?';
    }
}

 

after I posted I tried it like this:

 

if (isset($_POST['Submit'])) {
    if (isset($_SESSION['correct'])) $correct = $_SESSION['correct'];

    if (isset($_POST[$correct])) {
    echo 'you were right!';
    } else {
        echo '...might you be a bot?';
    }
}

 

And that decided to work... not sure what the big deal was between the both methods..

 

thanks! :-*

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.