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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    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();
    printEasyContro lPanelOptions() ;
    endPage();
    } else {
    if ($choiceMade) {
    $choiceMade();
    } else {
    printDefaultScr een();
    }
    }




    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?
  • Per Gustafsson

    #2
    Re: my code has gone complete mad and no longer does anything rational

    lawrence wrote:[color=blue]
    > 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:[/color]

    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.
    [color=blue]
    > $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?[/color]

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


    Per Gustafsson

    --



    Comment

    • lawrence

      #3
      Re: my code has gone complete mad and no longer does anything rational

      Actually, the whole site has gone made. If I look at this page:


      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 mostRecentComme nts($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->getAllTypeFrom Db("comments") ;
      $dbArray = array_reverse($ dbArray);
      print_r($dbArra y);
      echo "<div class=\"recentC omments\">";
      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=\"recentC ommentsEach\">< a
      class=\"recentC ommentLinks\" href=\"$comment Link\">\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";
      }

      Comment

      • lawrence

        #4
        Re: my code has gone complete mad and no longer does anything rational

        "Per Gustafsson" <per@pergustafs son.com> wrote in message[color=blue]
        > 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.[/color]

        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
        printDefaultScr een(); (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_COOK IE_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();
        //}




        [color=blue][color=green]
        > > $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?[/color]
        >
        > Only if $simpleMode carries the value "y". Also, an empty $choiceMade
        > would give a fatal error if those lines are executed.[/color]

        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("mcConf ig.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_COOK IE_VARS)) {
        // echo "here's the '$key' cookie: $val <br><br>\n\n\n" ;
        //}

        //$choiceMade = $_GET["choiceMade "];
        //if ($choiceMade) {
        // $choiceMade();
        //} else {
        printDefaultScr een();
        //}


        ?>

        Comment

        • lawrence

          #5
          Re: my code has gone complete mad and no longer does anything rational

          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("mcIncl udes/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_persist ent"] = 0;
          $config["db_databas e"] = 'xxx';
          $config["db_server"] = 'localhost';
          $config["db_user"] = 'xxx';
          $config["db_passwor d"] = 'xxx';
          $config["db_port"] = 3306;

          // these next few addresses are given has web Urls
          $config["nameOfDoma in"] = '.monkeyclaus.o rg';
          $config["linkToDS"] = "<a
          href='mcControl Panel.php?passw ord=$password'> Click here to get back to
          the control panel screen.</a><br>\n\n";
          $config["linkToWebS ite"] = "<a
          href='http://www.monkeyclaus .org/index.php'>Clic k here to go to the
          front page of your web site.</a><br>\n\n";
          $config["filesFolde r"] = "http://www.monkeyclaus .org/mcFiles/";
          $config["imagesFold er"] = "http://www.monkeyclaus .org/mcImages/"; //
          This is the url version of the address, not the host version
          $config["linkToLogi n"] = "<div class='dvcllink ToLogin'><a
          href='mcControl Panel.php'>logi n</a></div> \n\n";
          $config["pathToInde x"] ="http://www.monkeyclaus .org/index.php"; //
          this has to include the index page in the address.
          $config["pathToDatabase "] = "<a href='http://mysql.catalog.c om/'>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["pathToImageFol der"] =
          "/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcImages/"; //this needs
          to be set from the site root, obviously
          $config["pathToFileFold er"] =
          "/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcFiles/"; //this needs
          to be set from the site root, obviously
          $config["pathToNeededFi les"] =
          "/usr/local/www/vhosts/monkeyclaus.org/htdocs/mcIncludes/"; //this
          needs to be set from the site root, obviously


          $config["sentTo"] = "lkrubner@geoci ties.com, peter@monkeycla us.org,
          matt@monkeyclau s.org";
          $config["adminEmail "] = "lawrence@krubn er.com, peter@monkeycla us.org,
          matt@monkeyclau s.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"] = "monkeyclau s - who says you can't disguise a
          social movement as a music label?";
          $config["siteDescriptio n"] = "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($pathTo NeededFiles) or die("Can't open page");

          while ($theDirFiles = readdir($theDir )) {
          if ($theDirFiles != "." && $theDirFiles != ".." && $theDirFiles !=
          "mcControlPanel .php" && $theDirFiles != "mcConfig.p hp" && $theDirFiles
          != "index.php" ) {
          $theDirFiles = $pathToNeededFi les.$theDirFile s;
          include_once($t heDirFiles);
          }
          }
          }

          getNeededFiles( );

          $toBeExtracted = $config;
          extract($toBeEx tracted);
          // 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_pers istent, $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);

          ?>

          Comment

          Working...