bbmak Posted January 12, 2008 Share Posted January 12, 2008 Hi, I used to built script with register global on in php 4, but after they released php 5, register global is off the problem is I used " if ($action == " in my script. The script will show error " Notice: Undefined variable: action in...." in php 5 with default register global off Although, I can build the script will an emulation of register global on with the following code <? // Emulate register_globals on if (!ini_get('register_globals')) { $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET); if (isset($_SESSION)) { array_unshift($superglobals, $_SESSION); } foreach ($superglobals as $superglobal) { extract($superglobal, EXTR_SKIP); } } ?> I want to know how do I overcome this problem? I want to use 'if ($action ==' but i want the register global stays off. I do not always want to use register global emulation script and I do not want to make the php5 to register global on. Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/ Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 Use $_GET, $_POST, or $_REQUEST instead. Example: $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; http://us.php.net/reserved.variables Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-436983 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Where does $action variable get set at? Is it a POST or a GET form somewhere? Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-436984 Share on other sites More sharing options...
tapos Posted January 12, 2008 Share Posted January 12, 2008 You can use: if (!ini_get('register_globals')) { extract($_REQUEST); extract($_SERVER); } after using this u can use following stuff if($action) -- Thanks, Tapos Pal http://tapos.wordpress.com Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-437030 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 Yes, you can do that tapos, but this is old style and outdated way of doing things. Also, why create and use up extra memory with more variables when they're all already populated in predefined variables for you. Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-437033 Share on other sites More sharing options...
bbmak Posted January 12, 2008 Author Share Posted January 12, 2008 Yes, you can do that tapos, but this is old style and outdated way of doing things. Also, why create and use up extra memory with more variables when they're all already populated in predefined variables for you. toplay can you show me how to replace my code here with $_request ??? if ($action == 'show') { ... } what is the colon for : ? in this $_REQUEST['action'] : ??? Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-437041 Share on other sites More sharing options...
jitesh Posted January 12, 2008 Share Posted January 12, 2008 If you have any common file. like as DB connection or Config file which is included in all files Then you can metion. extract($_REQUEST); in first line. This is just temporaly solution. Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-437047 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 toplay can you show me how to replace my code here with $_request ??? if ($action == 'show') { ... } what is the colon for : ? in this $_REQUEST['action'] : ??? $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; if ($action == 'show') { ... } To know more about the ? : syntax, look for ternary operator info on this manual page: http://us.php.net/manual/en/language.operators.comparison.php Link to comment https://forums.phpfreaks.com/topic/85628-solved-register-global-off-notice-undefined-variable-action-in-problem/#findComment-437091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.