Jump to content


Photo

Notice: Undefined variable


  • Please log in to reply
6 replies to this topic

#1 Klaus_Lo

Klaus_Lo

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 09 June 2014 - 09:03 AM

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.



#2 trq

trq

    Advanced Member

  • Administrators
  • 31,032 posts
  • LocationSydney, Australia.

Posted 09 June 2014 - 10:47 AM

Line 31 of that first snippet is not valid php at all. It looks more like JavaScript.

We need more context.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#3 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,920 posts
  • LocationCanada

Posted 09 June 2014 - 11:06 AM

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, 09 June 2014 - 11:08 AM.

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#4 cyberRobot

cyberRobot

    Advanced Member

  • Gurus
  • 1,785 posts

Posted 09 June 2014 - 03:57 PM

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


Blogging about PHP and other web-related topics at ScorpBytes.com


#5 cyberRobot

cyberRobot

    Advanced Member

  • Gurus
  • 1,785 posts

Posted 09 June 2014 - 04:07 PM

"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/r...les.session.php


Blogging about PHP and other web-related topics at ScorpBytes.com


#6 trq

trq

    Advanced Member

  • Administrators
  • 31,032 posts
  • LocationSydney, Australia.

Posted 09 June 2014 - 05:45 PM

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

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#7 QuickOldCar

QuickOldCar

    Advanced Member

  • Members
  • PipPipPip
  • 1,960 posts
  • LocationNorthEast Pennsylvania

Posted 21 June 2014 - 10:22 PM

Why is php updated to version 5.2.17 and not like 5.5+


DynaIndex.com
Dynamic search index of websites, links, feeds, title, description, keywords and thumbnail snapshot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com