W
wilsonodk

  • Jan 27, 2006
  • Joined Aug 17, 2002
  • PHP 4 isn't OOP, it has OOP support for user defined objects, so there isn't a Object Model per say, like you find with Javascript or other OOP languages. The link I gave you will have most, if not all, the information you'll find on PHP 4 and PHP 5 "Object Models."

    • Too many double quotes:

      160) $config_data .= '"'.addslashes($value).'"';
      • Specifically, there are a few things that that one line make me wonder about.

        First, you are assigning 'PCP.profil.profile_prefer' what is that? Under normal circumstances, you can't assign a string a value. That makes me wonder if there isn't an error before the line.

        Second, after 'profilcp_prefer_shortcut' there is a comma that looks very suspicious. I don't think it belongs.

        Finally, after 'PCP.profil.profile_prefer.base' => array() there is a comma that looks very suspicious.

        It seems like you're building a very large array. If this is the case, I'd suggest breaking it into smaller bits to ease debugging.

        // Like this
        $yourarray['PCP.profil.profile_prefer'] = array('custom' => 1,'title' => 'profilcp_prefer_shortcut');
        $yourarray['PCP.profil.profile_prefer.base'] = array();
        • Regular Expressions are definitely not easy to decipher at first glance. 🙂

          I found that JavaScript: The Definitive Guide does a good job explaining them. Your milage may vary.

          • I don't think you'll find a one-size-fits-all script. I've looked. 🙂

            The reality is that all forms need to be validated in different ways. You'll find that there will be times where you don't allow any HTML from a text area, and other times where you'll let some tags through. It varies. I'd recommend building some scripts that you can carry from project to project and alter easily to suit your needs.

            Then again, maybe I haven't looked hard enough for the Holy Grail of form validation.

            • Note that you don't even need to force them to save them with particular file names if you do something like this:

              if ($handle = opendir('/path/to/files')) {
                while (false !== ($file = readdir($handle))) {
                  // Check if $file is a file
                  if (is_file($file)) {
                    // Check if it's an .xml file
                    if (strpos($file,'.xml') !== false) {
                      /* This is an XML file */
                      $xml[] = simplexml_load_file('/path/to/files/'.$file);
                    }
                  }
                }
              }
              
              /* We've loaded all our XML files
              We can now loop over $xml and gather page content */
              

              Good luck to you!

              • Hmm, interesting dilemma. Looks like you'd need some way to create dynamic filenames. Possibly store all the XML files in a single directory, then load all the XML from that directory. You'd need to use opendir and readdir. Though, if you do this, you'll end up loading far more XML files than you need to display.

                A way around that, is to pre-filter the XML files by placing them into particular sub-directories. This would decrease the number of XML files you needed to load each time you increased the level of the sub-directories.

                • I haven't tried it myself, but could you just have multiple calls to simplexml_load_file()?

                  $xml[0] = simplexml_load_file('file1.xml');
                  $xml[1] = simplexml_load_file('file2.xml');

                  Then you can grab the information you need for all the different XML files.

                  • You're getting the "Could not log you in" message for two reasons.

                    if (isset($_SESSION['valid_user'])) // Is not set
                      {
                        echo "You are logged in as: $valid_user <br>";
                        echo "<a href=\"logout.php\">Log out</a><br>";
                      }
                      else
                      {
                        if (isset($first)) // Is set
                        {
                          // Therefore this prints
                          echo "Could not log you in";
                        }
                        else 
                        {
                          echo "You are not logged in.<br>";
                              }
                        }
                    • If you need to show variables in the URL, use the GET method instead. So, you'll pass variables with $GET instead of $POST.

                      • It will be a "pain" as you definitely need more code logic, but it's not that much more.

                        // Code sample
                        // Function that will add spaces to a str
                        function addSpaces($intNumOfSpaces) {
                            $i=0;
                            $output='';
                            while ($intNumOfSpaces!=$i) {
                                $output.=" "; // possibly need &nbsp;
                                $i++;
                            }
                            return $output;
                        }
                        
                        // $lines is an array of all the lines you need to output.
                        // Get $line_lengths, and $longest_line
                        $longest_line = 0;
                        for ($i=0;$i<count($lines);$i++) {
                            $line_lengths[$i]=strlen($lines[$i]);
                            if ($line_lengths[$i] > $longest_line) $longest_line = $line_lengths[$i];
                        }
                        
                        // Add spaces to $lines
                        for ($i=0;$i<count($lines);$i++) {
                            if ($line_lengths[$i]==$longest_line) {
                                // No spaces needed
                                echo $lines[$i];
                            } else {
                                // Add spaces
                                echo $lines[$i].addSpaces($longest_line-$line_lengths[$i]);
                            }
                        }
                        

                        Would it be possible to store the line length in the database? That would take out the need for one of the loops.

                        • You can use strlen to figure out how long a string is. But, you'll still need some logic to know how many spaces to add. You could collect all the lines together with their length. Then determine which one is the longest. And add spaces to all the others based on the difference.

                          • No, you need something along the lines of...

                            if ($result = @mysql_query($sql)) { 
                              //echo md5($_POST['password']); 
                              //setcookie ("wfcookie", "you are logged in", time()+3600); 
                              session_start(); 
                              $_SESSION['$selection'];
                              while ($row = mysql_fetch_array($result)) {
                                echo 'poo' . $row['username']; 
                                echo $selection; 
                              }
                            }
                            • Use strstr or strpos.

                              According to the manual, you should always use strpos if you're just trying to find a needle in a haystack.

                              if (strpos($needle,$haystack)===false) {
                                  // Needle is NOT in the Haystack
                              } else {
                                  // Needle is in the Haystack
                              }
                              • Maybe try passing the connection link id through each method call, like this...

                                <?php 
                                
                                class mysql_db 
                                { 
                                    var $dblink; 
                                
                                
                                function mysql_db() 
                                { 
                                    $this->dblink = mysql_connect('localhost','root','') or die(mysql_error()); 
                                    mysql_select_db('hotels') or die(mysql_error()); 
                                } 
                                
                                function query($query) 
                                { 
                                    return mysql_query($query,$this->dblink) or die(mysql_error()); 
                                
                                } 
                                
                                function fetchArray($results) 
                                { 
                                    return mysql_fetch_array($results,$this->dblink) or die(mysql_error()); 
                                } 
                                
                                } 
                                ?>
                                • You could use

                                  preg_match()

                                  .

                                  ...
                                  elseif (preg_match ("/\d/", $_POST['fname'])) 
                                  { 
                                  die("Invalid first name!  Press the BACK button and edit the first name."); 
                                  ...

                                  That will catch any numeric value in a name.

                                  • You have to make sure to use { and } when doing that.

                                    $foo['bar'] = "blah";
                                    // Error
                                    echo "Oh $foo['bar']";
                                    // No error
                                    echo "Oh {$foo['bar']}";
                                    

                                    HTH