468,241 Members | 1,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

my code has gone complete mad and no longer does anything rational

Maybe its late and I'm tired but I don't understand what I'm seeing on
the screen. I have this block of code:

$choiceMade = $_GET["choiceMade"];
if ($simpleMode == "y" && $choiceMade == "") {
startPage();
printEasyControlPanelOptions();
endPage();
} else {
if ($choiceMade) {
$choiceMade();
} else {
printDefaultScreen();
}
}


Normally $choiceMade is handed something from the code and then
executes it. It is supposed to be the name of a function. About an
hour ago it started printing out the seconds, a unix timestamp.
Instead of executing a function, it just prints a time stamp. I
thought perhaps somehow the value of $choiceMade was getting
overwritten by a coookie. That is when I added the line you see at
top, where it grabs the value out of $_GET. I did this to test the
possibility that an errant cookie was screwing things up. However, the
problem persists, though the query string is empty. When the url looks
like this:

mcControlPanel.php
$choiceMade continues to print a timestamp. How is this possible? Why
isn't it blank? It should fail the if() test and print the default
screen, shouldn't it?
Jul 16 '05 #1
4 2058
lawrence wrote:
Normally $choiceMade is handed something from the code and then
executes it. It is supposed to be the name of a function. About an
hour ago it started printing out the seconds, a unix timestamp.
Instead of executing a function, it just prints a time stamp. I
thought perhaps somehow the value of $choiceMade was getting
overwritten by a coookie. That is when I added the line you see at
top, where it grabs the value out of $_GET. I did this to test the
possibility that an errant cookie was screwing things up. However, the
problem persists, though the query string is empty. When the url looks
like this:
It's quite hard to give any advice on such a short code snippet, I'd
rather see a larger part of your code which could actually be tried
without getting undefined functions messages.
$choiceMade continues to print a timestamp. How is this possible? Why
isn't it blank? It should fail the if() test and print the default
screen, shouldn't it?


Only if $simpleMode carries the value "y". Also, an empty $choiceMade
would give a fatal error if those lines are executed.
Per Gustafsson

--
http://www.pergustafsson.com/
Jul 16 '05 #2
Actually, the whole site has gone made. If I look at this page:
http://www.monkeyclaus.org/index.php?pageId=251

Using Netscape 7 on a PC, then it partially renders, then dies.
Strangely the page source shows a little more than what it is willing
to render on screen.

If I use AOL, which I think has a version IE in it, I first get a
"Page Not responding" error, then, on second attempt, a brief momenet
when it begins to render, then cancels, and then, if I keep hitting
the "refresh" button, I just get 404 type "page can not be rendered"
messages. Mind you, I can simultanesouly look at a portion of the page
in Netscape, though it does not render at all in AOL.
This is the function where the code seems to be dying (a function that
worked fine for months and to which I've made no changes). Someone
made the intelligent remark that the script might be dying elsewhere
than I think, but because of buffering what shows up in the browser
will be different than what the script has actually done.

When I added the print_r() line to this comment, suddenly more of the
page began to show. Instead of dying with this function, the page got
a little beyond it, and died elsewhere. Clearly, adding print_r() to a
function should not make it work.

I'm swimming in deep water at this point. If the browser isnt' going
to show me where the script is dying, then how do I test for the
problem?



function mostRecentComments($number=10) {
global $sql, $config;
extract($config);
// 06-17-03 - So the purpose of this function is to allow the
designer to list blurbs from recent comments
// in the margins. The number of comments returned is variable,
depending on the number given as an argument
// to the function. If it is 20 then the most recent 20 comments get
returned. The title or headline of the
// comment gets wrapped in a link so people can go read it, and from
there of course, they can link back to
// the page on which it is posted.
$dbArray = $sql->getAllTypeFromDb("comments");
$dbArray = array_reverse($dbArray);
print_r($dbArray);
echo "<div class=\"recentComments\">";
echo "These are the most recent $number comments:<br>";
for ($i=0; $i < $number; $i++) {
$row = $dbArray[$i];
$date = outputDate($row[3], 1);
$commentLink = $pathToIndex."?comment[]=";
$commentLink .= $row[0];
$row[2] = substr($row[2], 0, 80);
$row[2] = strip_tags($row[2]);
echo "<div class=\"recentCommentsEach\"><a
class=\"recentCommentLinks\" href=\"$commentLink\">\n";
echo $row[1];
echo "</a>\n";
echo " - ";
echo $row[2];
echo "... ";
echo "<br>\n";
echo $date;
echo "</div>\n\n";
}
echo "</div>";
echo "this is us after the end";
}
Jul 16 '05 #3
"Per Gustafsson" <pe*@pergustafsson.com> wrote in message
It's quite hard to give any advice on such a short code snippet, I'd
rather see a larger part of your code which could actually be tried
without getting undefined functions messages.


Below you'll see the whole page. This is the control panel, what you
see happening at this level is happening in global space. As I look at
this code, I see nothing that could effect $choiceMade.

I've been conducting some experiments and getting interesting results.
If I test for $choiceMade at the top of the page and assign it a value
like this:

if (!$choiceMade) $choiceMade = "";

Then the script works almost as it should. It at least gets down to
printDefaultScreen(); (inside that function it then fails for strange
reasons).
This code has been working for more than year, and then last night it
stopped working. I've been assuming that somewhere else in the code I
made some change that began to overwrite $choiceMade with the wrong
value, perhaps an errant cookie, but some of what is going on seems
to be happening on this page.

For instance, when these lines are uncommented:

//while (list($key, $val) = each($HTTP_COOKIE_VARS)) {
// echo "here's the '$key' cookie: $val <br><br>\n\n\n";
//}

Then the value of $choiceMade becomes "p". I don't see how. The "p"
could be the first letter from the name of the cookie "password", but
I can't see how this while loop is assigning it to $choiceMade.
Nevertheless, the experiment is simple:

If I don't have that first line, where I assign $choiceMade an empty
string, and if the while loop is commented out, then $choiceMade has
the value of a unix timestamp. I get the error, "Undefined function
1509432001()" (i just made up that number).

But if I uncomment the while loop, then I get the error, "Undefined
function p();"
These lines were also changing the value of $choiceMade, until I
commented them out:
//if ($builtInPage) {
// showBuiltInPage($builtInPage);
// die();
//}


$choiceMade continues to print a timestamp. How is this possible? Why
isn't it blank? It should fail the if() test and print the default
screen, shouldn't it?


Only if $simpleMode carries the value "y". Also, an empty $choiceMade
would give a fatal error if those lines are executed.


That would be the correct behavior. I've been meaning to add a catch
for empty $choiceMade's, so the software can fail gracefully, but it
is low on my priority list. This code you see was working for more
than a year, and now it is not, and I'm trying to figure out why.



<?php
//if (!$choiceMade) $choiceMade = "";
include("mcConfig.php");
extract($config);

// 06-20-03 - this next line deletes from the database any entry that
was marked for deletion at least a week or more ago.
$sql->clear();
$sql->turnSecurityOn();
checkPassword();
//if ($builtInPage) {
// showBuiltInPage($builtInPage);
// die();
//}

//while (list($key, $val) = each($HTTP_COOKIE_VARS)) {
// echo "here's the '$key' cookie: $val <br><br>\n\n\n";
//}

//$choiceMade = $_GET["choiceMade"];
//if ($choiceMade) {
// $choiceMade();
//} else {
printDefaultScreen();
//}
?>
Jul 16 '05 #4
Actually, it now seems to me that all of my global variables are being
overwritten or ignored, and in ways that seem completely random.
Consider:

On www.monkeyclaus.org the index page consists of just two lines of
code:
include("mcIncludes/mcConfig.php");
runMainLoop();

The included config file is below (with passwords x out). You'll see
that all config info is in a large associative array which should be
in global space on index.php after it is included. And yet I'm now
getting errors where functions use the global keyword to import
$config, and then hit it with extract(), but extract is complaining
that it needs to be handed an array. This is another thing that was
working yesterday morning and now is not.


<?php
define("ECLIPSE_ROOT",
"/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcIncludes/");

global $PHP_SELF;
$self = $PHP_SELF;
$config["self"] = $self;
global $password;

// this next is the root level password for the site.
$config["mcUserName"] = "xxx";
$config["mcPassword"] = "xxx";

// these next 6 variables are needed for Costin's database class:
$config["db_persistent"] = 0;
$config["db_database"] = 'xxx';
$config["db_server"] = 'localhost';
$config["db_user"] = 'xxx';
$config["db_password"] = 'xxx';
$config["db_port"] = 3306;

// these next few addresses are given has web Urls
$config["nameOfDomain"] = '.monkeyclaus.org';
$config["linkToDS"] = "<a
href='mcControlPanel.php?password=$password'>Click here to get back to
the control panel screen.</a><br>\n\n";
$config["linkToWebSite"] = "<a
href='http://www.monkeyclaus.org/index.php'>Click here to go to the
front page of your web site.</a><br>\n\n";
$config["filesFolder"] = "http://www.monkeyclaus.org/mcFiles/";
$config["imagesFolder"] = "http://www.monkeyclaus.org/mcImages/"; //
This is the url version of the address, not the host version
$config["linkToLogin"] = "<div class='dvcllinkToLogin'><a
href='mcControlPanel.php'>login</a></div> \n\n";
$config["pathToIndex"] ="http://www.monkeyclaus.org/index.php"; //
this has to include the index page in the address.
$config["pathToDatabase"] = "<a href='http://mysql.catalog.com/'>Go to
the database</a><br> \n";

// These next few addresses are not web urls, rather, they need to be
given as the directory paths on the host computer
$config["pathToImageFolder"] =
"/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcImages/"; //this needs
to be set from the site root, obviously
$config["pathToFileFolder"] =
"/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcFiles/"; //this needs
to be set from the site root, obviously
$config["pathToNeededFiles"] =
"/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcIncludes/"; //this
needs to be set from the site root, obviously
$config["sentTo"] = "lk******@geocities.com, pe***@monkeyclaus.org,
ma**@monkeyclaus.org";
$config["adminEmail"] = "la******@krubner.com, pe***@monkeyclaus.org,
ma**@monkeyclaus.org";
$config["simpleMode"] = 'n'; // 04-05-03 - set this line to 'n' if you
don't need the easy interface, you'll be presented with full options
instead.

$config["siteTitle"] = "monkeyclaus - who says you can't disguise a
social movement as a music label?";
$config["siteDescription"] = "local music, global awareness -
monkeyclaus has given everyone of its artists their own weblogs to
empower the voices of progressive cultural explorers.";
function getNeededFiles($needed = "all") {
global $config;
extract($config);
// open the directory and load all the files into the array
$theDir = opendir($pathToNeededFiles) or die("Can't open page");

while ($theDirFiles = readdir($theDir)) {
if ($theDirFiles != "." && $theDirFiles != ".." && $theDirFiles !=
"mcControlPanel.php" && $theDirFiles != "mcConfig.php" && $theDirFiles
!= "index.php") {
$theDirFiles = $pathToNeededFiles.$theDirFiles;
include_once($theDirFiles);
}
}
}

getNeededFiles();

$toBeExtracted = $config;
extract($toBeExtracted);
// 05-08-03: what follows are the classes that the procedural code
depends on. These need to be in global $forms, $io, $users, $links,
$sql, space.
// 06-21-03 - these used to be at the top of both index.php and
mcControlPanel.php. I'm going to try putting them here.
// 07-04-03 - starting today, all classes passed as parameters are
passed by reference. Before I unthinkingly passed them as
// copies and ended up with 4 copies of $sql in my code, and the
copies that existed inside the other objects did not have
// security turned on by the call to startUserMode() done here in
global space.
$db = new CMySQL($db_persistent, $db_database, $db_server, $db_user,
$db_password, $db_port);
$io = new McInputOutput();
$format = new McFormatting();
$output = new McOutput();
$validate = new McValidate();
$sql = new McSql($db, $io);
$users = new McUser($sql, $io, $config);
$nav = new McNav($sql, $io, $config);
// 07-04-03 - I just changed $links to $nav. This next line will be
needed for awhile for backwards compatibility.
$links = $nav;
$forms = new McForms($sql, $io, $config, $nav);

$render = new McPageRender();
//$sql->startUserMode($users);

?>
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

242 posts views Thread by James Cameron | last post: by
67 posts views Thread by Steven T. Hatton | last post: by
17 posts views Thread by wana | last post: by
18 posts views Thread by Joe Fallon | last post: by
171 posts views Thread by tshad | last post: by
1 post views Thread by KiMcHeE | last post: by
5 posts views Thread by shuisheng | last post: by
3 posts views Thread by RvGrah | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.