Jump to content

non-understandable foreach warning

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Hello everyone..

I have used a web application that I wrote myself and it has been working great just until a few days ago. I don't know if the web hotel has done anything, but I can't understand what that could be either.

I use a code snippet to create a "sub-page select string" similar to tab-pages or wheatever. this is the function to generate them:

	function showpages($arr, $file, $default) {

		if ($_GET['page'] == '') {

			$page = $default;

		} else {

			$page = $_GET['page'];

		}

		foreach ($arr as $key => $value) {

			if ($page == $key) {

				echo $value;

			} else {

				echo "<a href='".$file."?page=".$key."'>".$value."</a>";

			}

			echo "   ";

		}

		echo "<br><br>";

	}

I use this function by sending in an named array with pagename->title
which php-page i am currently in and a default page if none selected.

$page['pop'] = 'Befolkning';

$page['troop'] = 'Trupper';

$page['build'] = 'Byggnader';

showpages($page, 'profile.php', 'pop');

which outputs the array parts in a row, with links on everyone but the one choosen.

Now to the new found problem, which has not occured before.
when a page is choosen, i.e. when the line has its "?page=xxxxx" part,
I get a warning:

Warning: Invalid argument supplied for foreach() 

But the warning ONLY occurs when a page is choosen. if there is no choosen page, it works as it always did before.

anyone got any ideas? do you understand the problem?

accesses with no page-parameter works,
accesses with page-parameter does no longer work, but generates an warning as above. worked fine until now.

absolute no modifications has been made to the code for months and this just happened a few days ago....

thanks in advance
Örjan

#2
wahkiz

wahkiz

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
U might want to change the name of your array =D

$page and $_GET['page'] might be clashed somehow ^^

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
hmm.. somehow, "register globals" must have been activated, you mean? *sigh*
is there a way to turn it off by manual code?