Riparian Posted December 17, 2015 Share Posted December 17, 2015 10 years ago I wrote a large site without declaring the variables which was no problem at the time. For the last few years it has been the head-in-the-sand approach but now I have to make it right. There are thousands of these that kick out errors with register globals depreciated and this will eventually stop the site from working all together. Does anyone know of a simple or expedient way approach this problem ? Any help is greatly appreciated Cheers Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/ Share on other sites More sharing options...
Solution requinix Posted December 17, 2015 Solution Share Posted December 17, 2015 If you have stuff written from back when register_globals was acceptable then it's been a very long time and your code probably needs a once-over. Not just for this problem but potentially others. Otherwise the best thing you can do is fix the code. Really. It might take a while but all you need is stuff like $variable = (isset($_GET["variable"]) ? $_GET["variable"] : "reasonable default value");or if (isset($_GET["variable"])) { $variable = $_GET["variable"]; } else { // show an error } Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/#findComment-1528085 Share on other sites More sharing options...
Riparian Posted December 17, 2015 Author Share Posted December 17, 2015 Hello requinix Thank you for the reply... hmmm better go buy some more coffee ! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/#findComment-1528087 Share on other sites More sharing options...
Riparian Posted December 17, 2015 Author Share Posted December 17, 2015 Hello again and thank you for the code fix... I also get this error Notice: Undefined index: logout in ....... How would this one be addressed ? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/#findComment-1528088 Share on other sites More sharing options...
mac_gyver Posted December 17, 2015 Share Posted December 17, 2015 (edited) it depends is what the 'logout' index is intended to be a part of and how it is being used in the code. it could be $_POST, $_GET, or some other array. the context for each program variable that you are fixing needs to be taken into account. two other big problems you are going to have with older code that will require doing a rewrite are - 1) php used to try and escape input data, hoping that if you put it into an sql query statement, that it would prevent sql injection and sql special characters in the data from breaking the sql syntax. this 'feature' has been completely removed, so it's up to your code to either escape string data that's being used in sql query statements or use prepared queries. 2) the php version where the mysql_ database statements have been removed has already been released. if you or your web host upgrades to php version 7, all code that's using mysql_ functions will cease to work. the best choice for a replacement is to use the PDO class. this will also make using prepared queries the cleanest. if you really have 1000's of php variables that are affected by the removal of register_globals, it may be time to refactor your code to dynamically process and produce forms or dynamically produce logical pages using a single main page, using a data driven design, rather than to hard-code each and every variable, multiple times in any script or repeat pages that only differ in the content that's being displayed on them. producing a data driven design, also tends to result in DRY (Don't Repeat Yourself) programming, where repetitive program logic and markup are reduced, which in turn makes it easier to change or fix anything, since the logic or markup for any particular functionality only exists in the code once. Edited December 17, 2015 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/#findComment-1528089 Share on other sites More sharing options...
Riparian Posted December 17, 2015 Author Share Posted December 17, 2015 Thank you mac_gyver php used to be the program for dummies.... not any more .. the days of a hack knocking up a site with more than just a few pics on it are quickly disappearing ! Time for a full re-write by a professional me thinks. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/299793-help-with-register-globals/#findComment-1528093 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.