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
https://forums.phpfreaks.com/topic/76584-solved-huuuh-undefined-session/
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.

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! :-*

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.