Klaus_Lo Posted June 9, 2014 Share Posted June 9, 2014 Hello! Help me please! My site nice work on php version 5.2.12, but now php version is changed to 5.2.17 and some code is not working. It showing error: "Notice: Undefined variable: newCode in ....../humancheck.php on line 29" In file humancheck.php on line 29: for($i=0; $i<$config_max_digits;$i++) $newCode = $newCode.rand(0,9); This variable, it seems, taken from another file - humancheck_showcode.php: session_start(); $newCode = $HTTP_SESSION_VARS["newCode"]; And, in index.php file at the beginning of the file written: require ('human_check/humancheck.php'); And, in index.php file below is written: <IMG src="humancheck_showcode.php"> When I call the index.php file it shows error. So, I think, that variable "newCode" should be taken from file humancheck_showcode.php, but it don't do that. Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/ Share on other sites More sharing options...
trq Posted June 9, 2014 Share Posted June 9, 2014 Line 31 of that first snippet is not valid php at all. It looks more like JavaScript. We need more context. Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1482282 Share on other sites More sharing options...
Psycho Posted June 9, 2014 Share Posted June 9, 2014 (edited) Line 31 of that first snippet is not valid php at all. It looks more like JavaScript. What's not valid about this? for($i=0; $i<$config_max_digits;$i++) $newCode = $newCode.rand(0,9); Test: $config_max_digits = 10; $newCode = "CODE"; for($i=0; $i<$config_max_digits;$i++) $newCode = $newCode.rand(0,9); echo $newCode; Output: CODE9094108549 Edited June 9, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1482285 Share on other sites More sharing options...
cyberRobot Posted June 9, 2014 Share Posted June 9, 2014 What's not valid about this? for($i=0; $i<$config_max_digits;$i++) $newCode = $newCode.rand(0,9); To be honest, I thought the same thing. It took me longer than it should to realize that was a concatenation character between $newCode and rand(). I thought the OP was attempting to mix JS and PHP. Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1482336 Share on other sites More sharing options...
cyberRobot Posted June 9, 2014 Share Posted June 9, 2014 "Notice: Undefined variable: newCode in ....../humancheck.php on line 29" In file humancheck.php on line 29: for($i=0; $i<$config_max_digits;$i++) $newCode = $newCode.rand(0,9); This variable, it seems, taken from another file - humancheck_showcode.php: session_start(); $newCode = $HTTP_SESSION_VARS["newCode"]; The undefined variable message is coming from your humancheck.php script. Is the SESSION variable being read into that script? Side note: $HTTP_SESSION_VARS has been deprecated; you'll want to use $_SESSION instead. More information can be found here: http://www.php.net/reserved.variables.session.php Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1482339 Share on other sites More sharing options...
trq Posted June 9, 2014 Share Posted June 9, 2014 It took me longer than it should to realize that was a concatenation character between $newCode and rand(). I thought the OP was attempting to mix JS and PHP. +1 Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1482347 Share on other sites More sharing options...
QuickOldCar Posted June 22, 2014 Share Posted June 22, 2014 Why is php updated to version 5.2.17 and not like 5.5+ Quote Link to comment https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/#findComment-1483013 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.