Jump to content

minidak03

Members
  • Posts

    63
  • Joined

  • Last visited

    Never

Posts posted by minidak03

  1. I don't think I have enough information to fully help you here but have you thought about using include_once instead of include

     

    Trust me that is a dumb response to consider but we are dealing with Internet Explorer here Microsoft does some really messed up things.

     

    Does this still happen in FireFox?

     

    I don't see any issues in your code but double check for the period in your include files or post more of your code.

  2. If you want to play with ZIPs and PHP have a look at this chunk of code it'll help with a lot of issues your faced with by using external classes.

     

      $createZip = new createZip();
    
      $fileName = 'YOURZIPNAME.zip';
      $createZip->addDirectory('DIRECTORYNAME');
      $createZip->forceDownload($fileName);
      @unlink($fileName);
    
    class createZip  {
    
        public $compressedData = array();
        public $centralDirectory = array(); // central directory   
        public $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
        public $oldOffset = 0;
    
        /**
         * Function to create the directory where the file(s) will be unzipped
         *
         * @param $directoryName string
         *
         */
         
        public function get_files_from_folder($directory, $put_into) {
        if ($handle = opendir($directory)) {
          while (false !== ($file = readdir($handle))) {
            if (is_file($directory.$file)) {
              $fileContents = file_get_contents($directory.$file);
              $this->addFile($fileContents, $put_into.$file);
            } elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) {
              $this->addDirectory($put_into.$file.'/');
              $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/');
            }
          }
        }
        closedir($handle);
      }
        
        public function addDirectory($directoryName) {
            $directoryName = str_replace("\\", "/", $directoryName);  
    
            $feedArrayRow = "\x50\x4b\x03\x04";
            $feedArrayRow .= "\x0a\x00";    
            $feedArrayRow .= "\x00\x00";    
            $feedArrayRow .= "\x00\x00";    
            $feedArrayRow .= "\x00\x00\x00\x00";
    
            $feedArrayRow .= pack("V",0);
            $feedArrayRow .= pack("V",0);
            $feedArrayRow .= pack("V",0);
            $feedArrayRow .= pack("v", strlen($directoryName) );
            $feedArrayRow .= pack("v", 0 );
            $feedArrayRow .= $directoryName;  
    
            $feedArrayRow .= pack("V",0);
            $feedArrayRow .= pack("V",0);
            $feedArrayRow .= pack("V",0);
    
            $this -> compressedData[] = $feedArrayRow;
            
            $newOffset = strlen(implode("", $this->compressedData));
    
            $addCentralRecord = "\x50\x4b\x01\x02";
            $addCentralRecord .="\x00\x00";    
            $addCentralRecord .="\x0a\x00";    
            $addCentralRecord .="\x00\x00";    
            $addCentralRecord .="\x00\x00";    
            $addCentralRecord .="\x00\x00\x00\x00";
            $addCentralRecord .= pack("V",0);
            $addCentralRecord .= pack("V",0);
            $addCentralRecord .= pack("V",0);
            $addCentralRecord .= pack("v", strlen($directoryName) );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $ext = "\x00\x00\x10\x00";
            $ext = "\xff\xff\xff\xff";  
            $addCentralRecord .= pack("V", 16 );
    
            $addCentralRecord .= pack("V", $this -> oldOffset );
            $this -> oldOffset = $newOffset;
    
            $addCentralRecord .= $directoryName;  
    
            $this -> centralDirectory[] = $addCentralRecord;  
        }    
        
        /**
         * Function to add file(s) to the specified directory in the archive
         *
         * @param $directoryName string
         *
         */
        
        public function addFile($data, $directoryName)   {
    
            $directoryName = str_replace("\\", "/", $directoryName);  
        
            $feedArrayRow = "\x50\x4b\x03\x04";
            $feedArrayRow .= "\x14\x00";    
            $feedArrayRow .= "\x00\x00";    
            $feedArrayRow .= "\x08\x00";    
            $feedArrayRow .= "\x00\x00\x00\x00";
    
            $uncompressedLength = strlen($data);  
            $compression = crc32($data);  
            $gzCompressedData = gzcompress($data);  
            $gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2);
            $compressedLength = strlen($gzCompressedData);  
            $feedArrayRow .= pack("V",$compression);
            $feedArrayRow .= pack("V",$compressedLength);
            $feedArrayRow .= pack("V",$uncompressedLength);
            $feedArrayRow .= pack("v", strlen($directoryName) );
            $feedArrayRow .= pack("v", 0 );
            $feedArrayRow .= $directoryName;  
    
            $feedArrayRow .= $gzCompressedData;  
    
            $feedArrayRow .= pack("V",$compression);
            $feedArrayRow .= pack("V",$compressedLength);
            $feedArrayRow .= pack("V",$uncompressedLength);
    
            $this -> compressedData[] = $feedArrayRow;
    
            $newOffset = strlen(implode("", $this->compressedData));
    
            $addCentralRecord = "\x50\x4b\x01\x02";
            $addCentralRecord .="\x00\x00";    
            $addCentralRecord .="\x14\x00";    
            $addCentralRecord .="\x00\x00";    
            $addCentralRecord .="\x08\x00";    
            $addCentralRecord .="\x00\x00\x00\x00";
            $addCentralRecord .= pack("V",$compression);
            $addCentralRecord .= pack("V",$compressedLength);
            $addCentralRecord .= pack("V",$uncompressedLength);
            $addCentralRecord .= pack("v", strlen($directoryName) );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("v", 0 );
            $addCentralRecord .= pack("V", 32 );
    
            $addCentralRecord .= pack("V", $this -> oldOffset );
            $this -> oldOffset = $newOffset;
    
            $addCentralRecord .= $directoryName;  
    
            $this -> centralDirectory[] = $addCentralRecord;  
        }
    
        /**
         * Fucntion to return the zip file
         *
         * @return zipfile (archive)
         */
    
        public function getZippedfile() {
    
            $data = implode("", $this -> compressedData);  
            $controlDirectory = implode("", $this -> centralDirectory);  
    
            return   
                $data.  
                $controlDirectory.  
                $this -> endOfCentralDirectory.  
                pack("v", sizeof($this -> centralDirectory)).     
                pack("v", sizeof($this -> centralDirectory)).     
                pack("V", strlen($controlDirectory)).             
                pack("V", strlen($data)).                
                "\x00\x00";                             
        }
    
        /**
         *
         * Function to force the download of the archive as soon as it is created
         *
         * @param archiveName string - name of the created archive file
         */
    
        public function forceDownload($archiveName) {
            $headerInfo = '';
            
            if(ini_get('zlib.output_compression')) {
                ini_set('zlib.output_compression', 'Off');
            }
    
            // Security checks
            if( $archiveName == "" ) {
                echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>";
                exit;
            }
            elseif ( ! file_exists( $archiveName ) ) {
                echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>";
                exit;
            }
    
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private",false);
            header("Content-Type: application/zip");
            header("Content-Disposition: attachment; filename=".basename($archiveName).";" );
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".filesize($archiveName));
            readfile("$archiveName");
            
         }
    
    } 
    

     

    The above class works for so many situations.

     

  3. Most of the time its not nessissary to do this because you won't need the entire object you'll just need there name for instance in which case you just store there name in the session.

     

    Also another reason not to do it is because sometimes you won't need to use sessions on all pages but you may need to access the object on that page, by storing that entire object in a session you'll have to re-open the session to get at it.

     

    Not the best argument in the book but you can also loose that session data with Internet Explorer and boom there goes your object, it makes it hard to troubleshoot through your code.

  4. First off yes varchar length is required.

     

    Second off there are lots of benefits of having NULL and NOT NULL for instance I always use NULL but not always haha (Talk about a contradiction).

     

    Lets say you have a database table with 3 fields which are A, B, and C.

     

    If you require field A and B to have data but sometimes you need to leave C empty then for C you would use NULL otherwise that field can never be empty and will probably cause an error or issues.

     

    Now lets say that I have another table with 3 fields which are D, E, and F and I place data in D and E but then F cannot be empty no matter what, lets say I'm using this value to determine the active status of a user where 0 means they are not activated and 1 means they are.

     

    So if I added a new user I always want that new user to be not active until I activate there account so if field F was my activation status field I would use NOT NULL with a default of 0 this way if I forget to add this value when doing my SQL statement it won't matter because it will default to 0 which in this case means the users status will not be active.

     

    There are tons of practical uses for each and I would suggest just thinking it through if you think you'll need to use NOT NULL with a default value then use it otherwise use NULL which means if other entires in that row has values one is allowed to be empty.

  5. You would do something like this

     

    include_once('external_library');
    
    class myClass {
        function myClassFun() {
            // now to use the outside function you can do this
            $class = new externalClass(); // assuming this is the name of the external class
            $something = $class->whatever();
        }
    }
    

     

    Please not in the little example above the var $class is only accessable inside of the function myClassFun.

  6. Try this out

     

    else if($_POST && $_POST['pass'] != $_POST['cpass'] || $_POST['pass'] == "" || $_POST['cpass'] == "" || $_POST['host'] == "" || $_POST['dbname'] == "") {

     

    To me there was a few bugs with your statement.

  7. This line seems wrong to me for some reason

     

    $encrypted_password = $db->getOne("SELECT password FROM users WHERE username = '$_POST[username]'");

     

    I think it should be more like this

     

    $encrypted_password = $db->getOne("SELECT password FROM users WHERE username = '".$_POST['username']."'");

     

    For your $_POST variable you didn't include any quotes around it.

     

    Try that out.

  8. $_SERVER["HTTP_REFERER"]

     

    Yes this will work but only if the other site sends the correct headers you can do something like

     

    if($_SERVER["HTTP_REFERER"] == 'www.specificsite.com'){// do code here}

     

    This will work about 99% of the time but again if the site is a bit messed up you may not get the information, its header specific.

  9. I would try using exceptions to catch the error / "exit" when the curl operation fails.

     

    http://www.php.net/exceptions

     

    You could also separate the code that checks the feed and inserts / deletes from the db into a file that can be executed independently...then have a controller script that forks off additional, background, processes to do the work...it would probably be faster, and it wouldn't kill the overall script.

     

    Cacti does this with it's snmp polling functionality.

     

    Unfortunately the try/catch sequence is only for PHP 5 and my host runs PHP 4.3.3 I already tried that one out even knowing its not supported to no avail.

     

    toplay,

     

    I'll give it a shot with the CURLOPT_TIMEOUT as well as a combination of others.

     

    Basically I've managed to somewhat figure out the problem more, basically from what I can tell is that the script dies when the curl_exec(); fires after which it doesn't make it to the next lines of code, its as if the curl_exec function causes a fatal error which kills the script completely and prevents any further execution but the really tricky thing is that it doesn't even return any kind of error to me I've used CURLOPT_FAILONERROR with some if statements to try and catch the any errors but again none are reported.

     

    Its a tough one because it works fine about 70% of the time with huge lists of URLs to check and it only seems to stop once it comes to an invalid URL or a URL in which the server does not send back a response from, then it hangs, I've found a few of the URLs which cause it to kill the script and tried visiting them as normal in the web browser but the page never seems to load, some even load much longer then the standard 30 second browser timeout.

     

    Its only on those non-loading URLs which cause the script to fail and not pass the function curl_exec(), basically my overall goal is to just simply verify the feeds that the URLs point to, after I grab a list of RSS feeds I send out the bot to check to see if the URL is valid and to see if the feed has any posts in it, if the feed doesn't have any posts or doesn't load then I take it out of my array and keep the good ones.

     

    I guess I'll have to experiment with some other ideas and see if I can troubleshoot this thing some more.

     

    P.S. I also just tried to break up the script so instead of grabbing the URLs and trying to verify them all in one process, It grabs the URLs (Just fine) then once the script stops I click a new validate button and run the script from a fresh start, I did this because I though maybe just maybe there is a setting in the php.ini file that is causing the problem but since my host doesn't give me access to the php.ini file I can't exactly check it.

  10. Ok this is my first post on the PHP Freaks forum but I've been around this place a lot and have read tons of articles, ect... I'm not new to PHP and I understand programming very well its what I do for a living most of the time so no need to give simple answers.

     

    Anyway I've got a problem that I cannot find a solution for anywhere, I've searched the PHP documentations, the PHP Freaks forum, website, and probably about 50 others in the past two days alone and the problem lies with my cURL timing out and completely killing my script.

     

    A brief overview of what I'm doing with it, first off I'm running PHP Version 4.3.3 and I've got a class set up to pharse rss feeds, now I've been using this class for a long time and it works great and never had a problem until now, the reason I think is because of the amount of feeds I'm trying to phrase through.

     

    I'm going through anywhere from 300 to 1000 or more feeds to verify that they actually have at least one single post to them, if they don't then I get rid of the feed URL and if they do then I keep that URL, anyway it seems like on certain feed urls that the page never loads, a response is never sent back by the calling machine so I said well I'll just set the cURL timeout option to say 20 seconds and if it times out then the script will continue to fire but the script doesn't continue to fire, when it times out it completely kills the script, wouldn't common sense say that a fatal error is causing this or that if cURL times out it should close and the script should continue on its marry way?, Basically I'm not getting any errors what so ever its just stopping the script all together after a timeout, here is the code I'm using.

     

    class xmlParser 
      {
         var $title;
         var $link;
         var $description;
         function xmlParser ($aa)
         {
             foreach ($aa as $k => $v)
                 $this->$k = $aa[$k];
         }
      }
      
      function readDatabase($filename)
      {
         $ch = curl_init();
         $timeout = 30; // set to zero for no timeout
         curl_setopt($ch, CURLOPT_URL, $filename);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 15);
         curl_setopt($ch, CURLFTPSSL_NONE, true);
         $data = curl_exec($ch);
         curl_close($ch);
    
         $parser = xml_parser_create();
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
         xml_parse_into_struct($parser, $data, $values, $tags);
         xml_parser_free($parser);
         
         if($tags)
         {
           foreach ($tags as $key => $val) {
               if ($key == "item") {
                   $molranges = $val;
                   for ($i = 0; $i < count($molranges); $i += 2) {
                           $offset = $molranges[$i] + 1;
                       $len = $molranges[$i + 1] - $offset;
                       $tdb[] = parseMol(array_slice($values, $offset, $len));
                   }
               } else {
                   continue;
               }
           }
         }
         return $tdb;
      }
      
      function parseMol($mvalues)
      {
         for ($i = 0; $i < count($mvalues); $i++) {
             $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
         }
         return new xmlParser($mol);
      }

     

    So to sum it up if I try to access a URL that takes forever to send a response back the cURL object reaches its timeout and kills the script, what I want it to do is once the timeout is reached don't completely kill the script but return a false value to the calling function and move on to verify the next URL.

     

    Any advice, suggestions, or points of view at this point would be a huge help.

     

    Thanks in advance.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.