Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/289081-notice-undefined-variable/
Share on other sites

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 by Psycho

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.  :-[

"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

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.