What if register_global is enabled

I have a simple captcha that works fine when register_global is disabled and this is correct according to the PHP manual Using global globals

But sometimes I switch to many hosting services, and they are included in the global register by default, so my captcha stops working and always gives the wrong code, even if it was entered correctly.

My question

why doesn't it work if register_global is on as well as off?

The code

captcha.php

<?PHP
session_start();
$digits_num=5;
$x_pos=25;
$y_pos=6;
$font_size=5;
function random_num($n){
$start_num = "1".str_repeat("0", $n-1);;
$end_num   = str_repeat("9", $n);
return rand($start_num, $end_num);
}
$text = random_num($digits_num);
$_SESSION["captcha_num"] = md5($text);
$captcha = imagecreatefrompng("./images/captcha.png");
$font_color['black']=imagecolorallocate($captcha, 0, 0, 0);
$font_color['white']=imagecolorallocate($captcha, 80, 73, 20);
imagestring($captcha, $font_size, $x_pos, $y_pos, $text, $font_color['white']);
header("Content-type: image/png");
imagepng($captcha);
?>

The form

<form name="frm" method="post" action="add.php">
<img src="captcha.php">
<input type="text" name="captcha_num" id="captcha_num" >
<input type="submit" name="submit" id="submit" value="submit">
</form>

add.php

<?PHP
session_start();
if(md5($_POST['captcha_num']) != $_SESSION['captcha_num']){
echo "Wrong captcha";
}else{
echo "Good Pass it";
}
?>
+3
source share
1 answer

On the manual page that you linked to:

DEPRECATED PHP 5.3.0 PHP 5.4.0
(...)
, PHP , PHP register_globals ON OFF PHP "4.2.0.

: .

?

1: ini_set

( , )

ini_set('register_globals', 'Off')

2: htaccess

.htaccess :

php_flag register_globals Off

, script , , , / .

+4

All Articles