What are register_globals in PHP?

Viewed 73620

Can someone give some examples of what register_globals are?
And is global $user_id; considered a register global?

8 Answers

register_globals is one of the parameters of php.ini file.The file was coming from "On" mode before PHP 5.3.8 version.If you change register_globals from Off to On, there would be some criticals about vulnerability of website.Register_globals's feature is that you can use variables without $_GET and $_POST variables.So, Any data which comes from form or URL line you can use the variable not need like $_GET or $_POST variables.Example we have this form :

<?php 
if(isset($_POST["myinput"])){
        echo $_POST["username"];
    }?>


<form action="" method="post">
    <input type="text" name="username">
    <input type="hidden" name="myinput">
    <input type="submit" value="Submit">
</form>

When you submitted the form you can see your username but when you change the situation of register_globals to "On" you have not written $_POST["username"]; you can access directly to the username variable by writing this code echo $username

Related