472,988 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

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 2298
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
17
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
1
by: KiMcHeE | last post by:
Hi! I'm having a real difficult time trying to figure out what is wrong with my program code. I'm trying to make a "calculator" in the C language and I only know basic stuff. Here's my code: ...
21
by: Goofy | last post by:
I see that the code behind is now a partial class. So where is the code associated with the server controls declaration etc ? Is this generated on the fly now, or am I missing something ? --...
5
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But...
3
by: RvGrah | last post by:
I seem to have acquired a strange issue here, some of my programs are now failing silently, resuming without notification that anything went wrong, both on my development machine and (I think) on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.