dstar101 Posted March 18, 2010 Share Posted March 18, 2010 Hi! I am new to PHP and I am still learning. In PHP when I tried to create File Uploading Script, at first it was not working but when I enabled "register_globals = ON" It is now working but in php.ini it says ; You should do your best to write your scripts so that they do not require ; register_globals to be on; Using form variables as globals can easily lead ; to possible security problems, if the code is not very well thought of. ; http://php.net/register-globals So My question is How I can write my script with out using globals register Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/ Share on other sites More sharing options...
Mchl Posted March 18, 2010 Share Posted March 18, 2010 Using $_POST and $_GET arrays: http://php.net/manual/en/language.variables.predefined.php Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028239 Share on other sites More sharing options...
DWilliams Posted March 18, 2010 Share Posted March 18, 2010 Well it depends what you're trying to do. If you just need some variables accessible from all your scripts (for example, config settings), then it's common to place them all in one file (for example, config.php or config.inc) and use require to load them into the current script. For example, if you have a config.php with the following contents: <?php $greeting = "Hello World!"; ?> and index.php with: <?php require('config.php'); echo "<h1>$greeting</h1>"; ?> Then $greeting would be displayed on the index page. Obviously not a particularly useful example but there are multitudes of variables that can be centralised with a config file (database connections, for example). Not sure if that answers your question or not Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028240 Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2010 Share Posted March 18, 2010 @DWilliams, register_globals has nothing at all to do with what you just posted. It concerns 'magically' populating program variables from the same name $_GET, $_POST, $_COOKIE, $_FILES, $_SESSION, $_SERVER, and $_ENV variables, thereby allowing hackers to set any program variables and $_SESSION variables instead of just the intended variables. Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028243 Share on other sites More sharing options...
dstar101 Posted March 18, 2010 Author Share Posted March 18, 2010 Thanks for the quick reply.. My Question is How to write scripts which do not require global_variables to be turn ON as the PHP sites says that it is deprecated in new versions Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028248 Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2010 Share Posted March 18, 2010 Mchl already addressed that. You write code that references the correct $_GET, $_POST, $_COOKIE, $_FILES, $_SESSION, $_SERVER, and $_ENV variables where the actual data is coming from. If you are using session_register(), session_is_registered(), or session_unregister(), you will need to make additional changes in the code to use the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028251 Share on other sites More sharing options...
dstar101 Posted March 19, 2010 Author Share Posted March 19, 2010 Thanks my problem is solved Quote Link to comment https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.