Notice: Undefined variable: newCode

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Klaus_Lo
Forum Newbie
Posts: 1
Joined: Mon Jun 09, 2014 9:13 am

Notice: Undefined variable: newCode

Post by Klaus_Lo »

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:

Code: Select all

for($i=0; $i<$config_max_digits;$i++)   $newCode = $newCode.rand(0,9); 
This variable $newCode, it seems, taken from another file - humancheck_showcode.php:

Code: Select all

session_start();
$newCode = $HTTP_SESSION_VARS["newCode"];
And, in index.php file at the beginning of the file written:

Code: Select all

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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Notice: Undefined variable: newCode

Post by requinix »

The variable wasn't "taken" from anywhere. PHP that executes for one request is completely separate from code that executes in another request, so the variables you set in humancheck_showcode.php have no bearing on the variables in humancheck.php - and vice versa.

Seems like humancheck.php needs a

Code: Select all

session_start();
$newCode = $_SESSION["newCode"];
of its own (which is the more modern version of what you have now).
Post Reply